<?php
/**
 *
 * 韦德教育 PPTS功能控制器模块
 * @author 窦子滨 <zibin_5257@163.com>
 * 
 */
class PPtsAction extends Action{
    function _initialize()  //控制器初始化方法，进行权限的认证
    {
         $System=D('System');
         $System->check_qx_model($_SESSION['qx_id'],3,1);
         unset ($System);
    }
    /**
     * 建立学员档案界面
     */
    public function create_stuinfo(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,2);
        unset ($System);
        //获取该用户的分公司部门id
        $PPTS=D('Ppts');
        $fgs_id=$PPTS->get_user_bmid($_SESSION['user_id'],'k');

        $this->assign('xq_id',$PPTS->get_user_bmid($_SESSION['user_id'],'s'));
        //dump($fgs_id);
        //
        //将该用户分公司的所有校区输出到模板
        $this->assign('xq_list',$PPTS->get_fgs_xq_list($fgs_id));

        unset($PPTS);

        

        $this->display();
    }

    /**
     * 保存并进行电子合同的录入
     */
    public function save_stuinfo(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,2);
        unset ($System);
        
        $Stuinfo=M('Stuinfo');
        $Stuinfo->create();
        $Stuinfo->user_id=$_SESSION['user_id'];
        $Stuinfo->stu_inputtime=  get_date_full(time());
        $stu_id=$Stuinfo->add();
        unset($Stuinfo);

//        $PPTS=D('Ppts');
//        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
//        unset($PPTS);
        //学员校区归属逻辑
        $SX=M('Stu_xiaoqu');
        $sx_data=array(
            'stu_id'=>$stu_id,
            'xq_id'=>(integer)addslashes($_POST['stu_xiaoqu']),
            'input_id'=>$_SESSION['user_id'],
            'input_time'=>get_date_full(time())
        );
        $SX->add($sx_data);
        unset($SX);

        if($stu_id){
            pop('学生基本信息档案建档成功，在分公司质控未审核通过之前，您还可以在学员档案管理中进行修改，但不能进行删除！', U('ppts/manger_stuinfo'));
        }else{
            pop('系统错误，请返回重新创建信息，如无法解决，请联系技术部解决！', 'javascript:history.go(-1);');
        }
    }
    /**
     * 咨询师对学员档案进行管理
     */
    public function manger_stuinfo(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,4);
        unset ($System);

        $this->assign('begin_day', $_GET['begin_day']);
        $this->assign('stop_day', $_GET['stop_day']);

        $begin_day=str_replace('_', '-',addslashes($_GET['begin_day']));
        $stop_day=str_replace('_', '-',addslashes($_GET['stop_day']));
        $stu_name=addslashes($_GET['stu_name']);

        $this->assign('stu_name', $stu_name);

        $shenhe=(integer)addslashes($_GET['shenhe']);
        $this->assign('shenhe', $shenhe);
        
        $sql_str='';
        if($shenhe!=''){
            if($shenhe!=99){
                $sql_str.="and shenhe='{$shenhe}'";
            }
        }
        


        if($begin_day!=''){
            $sql_str.="and stu_inputtime>='{$begin_day}' ";
        }
        if($stop_day!=''){
             $sql_str.="and stu_inputtime<='{$stop_day}' ";
        }

        if($stu_name!=''){
            $sql_str.="and stu_name='{$stu_name}' ";
        }


        $Stuinfo=M('Stuinfo');
        import("ORG.Util.Page"); // 导入分页类
        $count=$Stuinfo->where("user_id={$_SESSION['user_id']} {$sql_str}")->count();
        $Page=new Page($count,20); // 实例化分页类传入总记录数和每页显示的记录数
        $Page->setConfig('theme',"共计%totalRow%条记录 每页20条记录　当前%nowPage%/%totalPage% 页 %upPage% %downPage% %first%  %prePage%  <font color=red>%linkPage%</font>  %nextPage% %end%");
        $show=$Page->show(); // 分页显示输出
        $list=$Stuinfo->where("user_id={$_SESSION['user_id']} {$sql_str}")->field('stu_id,stu_name,stu_sex,stu_year,stu_school,stu_tel,stu_inputtime,shenhe,tidang')->order('stu_inputtime desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        




        //$list=$Stuinfo->where("user_id={$_SESSION['user_id']}")->field('stu_id,stu_name,stu_sex,stu_year,stu_school,stu_tel,stu_inputtime,shenhe')->order('stu_inputtime desc')->select();
        unset ($Stuinfo);
        //dump($list);
        $this->assign('stuinfo_list', $list);
        unset ($list);
        unset ($Page);
        //页码赋值到模板
        $this->assign('page', $show);
        $this->display();
    }


    /**
     * 咨询师查看自己的学员档案详细信息
     *
     * @var integer $_GET['id']  学员id编号 必须对其进行检查是否归属于该咨询师
     */
    public function view_zx_stu_info(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,4);
        unset ($System);
        //学员id编号
        $stu_id=(integer)addslashes($_GET['id']);
        $Stuinfo=M('Stuinfo');
        $list=$Stuinfo->where("lfy_stuinfo.stu_id={$stu_id} and user_id={$_SESSION['user_id']}")->join("lfy_stu_xiaoqu on lfy_stu_xiaoqu.stu_id=lfy_stuinfo.stu_id")->join("lfy_bumen on lfy_stu_xiaoqu.xq_id=lfy_bumen.bm_id")->find();
        //dump($list);
        unset ($Stuinfo);
        if(is_null($list)){
            pop_js('您没有权限浏览该条记录！','self.parent.tb_remove();self.parent.location.reload();');
        }
        $this->assign($list);

        unset ($list);
        $this->display();
    }

    /**
     * 咨询师对自己未通过审核的学员档案进行修改
     *
     * @var integer $_GET['id']  学员id 必须对其拥有性和是否通过审核进行检测
     */
    public function edit_zx_stu_info(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,4);
        unset ($System);
        //学员id编号
        $stu_id=(integer) addslashes($_GET['id']);
        $Stuinfo=M('Stuinfo');
        $list=$Stuinfo->where("stu_id={$stu_id} and user_id={$_SESSION['user_id']} and shenhe='0'")->find();
        unset ($Stuinfo);
        if(is_null($list)){
            pop_js('您没有权限修改该条记录或者该条记录已经通过审核！','self.parent.tb_remove();self.parent.location.reload();');
        }
        $this->assign($list);
        

         //获取该用户的分公司部门id
        $PPTS=D('Ppts');
        $fgs_id=$PPTS->get_user_bmid($_SESSION['user_id'],'k');
        //将该用户分公司的所有校区输出到模板
        $this->assign('xq_list',$PPTS->get_fgs_xq_list($fgs_id));
        unset($PPTS);


        $Stu_xiaoqu=M('Stu_xiaoqu');
        $this->assign('xq_id', $Stu_xiaoqu->where("stu_id={$list['stu_id']}")->getfield('xq_id'));
        unset ($list);
        unset($Stu_xiaoqu);
        
        $this->display();
    }

    /**
     * 保存咨询师对自己的未审核学员档案进行的修改
     *
     * @var array $_POST 学员档案信息组
     */
    public function save_zx_edit_stuinfo(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,4);
        unset ($System);
        //学员id编号
        $stu_id=(integer)addslashes($_POST['stu_id']);
        $Stuinfo=M('Stuinfo');
        $list=$Stuinfo->field('shenhe')->where("stu_id={$stu_id} and user_id={$_SESSION['user_id']} and shenhe='0'")->find();
        if(is_null($list)){
            pop_js('您没有权限修改该条记录或者该条记录已经通过审核！','self.parent.tb_remove();self.parent.location.reload();');
        }
        $Stuinfo->create();

        $Stu_xiaoqu=M('Stu_xiaoqu');
        $Stu_xiaoqu->where("stu_id={$stu_id}")->delete();

        $sx_data=array(
            'stu_id'=>$stu_id,
            'xq_id'=>(integer)addslashes($_POST['stu_xiaoqu']),
            'input_id'=>$_SESSION['user_id'],
            'input_time'=>get_date_full(time())
        );
        $Stu_xiaoqu->add($sx_data);
        unset($Stu_xiaoqu);


        if($Stuinfo->save()){
            unset ($Stuinfo);
            pop_js('学员档案修改成功！','self.parent.tb_remove();self.parent.location.reload();');
        }else{
            unset ($Stuinfo);
            pop_js('学员档案无修改无需保存或您无权修改该学员档案！','self.parent.tb_remove();self.parent.location.reload();');
        }
        unset ($Stuinfo);
    }

    /**
     * 分公司学员档案审核功能
     */
    public function fgs_stuinfo_shenhe(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,16);
        unset ($System);
         //建立学员基本信息模型
        $Stu_info=M('Stuinfo');
       //建立PPTS数据处理模型
        $PPTS=D('Ppts');
        $userid_str=$PPTS->get_bm_all_user($_SESSION['user_id'],'k');
        unset ($PPTS);

        import("ORG.Util.Page"); // 导入分页类
        $count=$Stu_info->where("(0 {$userid_str}) and shenhe='0' and tidang='1'")->count();
        $Page=new Page($count,20); // 实例化分页类传入总记录数和每页显示的记录数
        $Page->setConfig('theme',"共计%totalRow%条记录 每页20条记录　当前%nowPage%/%totalPage% 页 %upPage% %downPage% %first%  %prePage%  <font color=red>%linkPage%</font>  %nextPage% %end%");
        $show=$Page->show(); // 分页显示输出
        //查询所有属于该分公司用户未审核通过的学员档案列表
        $stu_list=$Stu_info->where("(0 {$userid_str}) and shenhe='0' and tidang='1'")->limit($Page->firstRow.','.$Page->listRows)->select();
        unset ($userid_str);
        unset ($Page);
        $this->assign('stuinfo_list', $stu_list);
        unset ($stu_list);
        //页码赋值到模板
        $this->assign('page', $show);
        $this->display();
    }


    /**
     * 分公司：学员档案审核，查看详细的学员基本信息
     *
     * @var integer $_GET['id']  需要查看的学员id
     */
    public function view_fgsshenhe_stu_info(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,16);
        unset ($System);
        $stu_id=(integer) addslashes($_GET['id']);
        $Stuinfo=M('Stuinfo');
        $list=$Stuinfo->where("stu_id={$stu_id} and shenhe='0'")->find();
        
        if(is_null($list)){
            pop_js('该条记录已经通过审核，无需再次审核！', 'self.parent.tb_remove();self.parent.location.reload();');
        }
        unset ($list);
        //建立PPTS数据处理模型
        $PPTS=D('Ppts');
        $userid_str=$PPTS->get_bm_all_user($_SESSION['user_id'],'k');
        
        unset ($PPTS);
        $list=$Stuinfo->where("(0 {$userid_str}) and stu_id={$stu_id} and shenhe='0'")->find();
        unset ($Stuinfo);
        if(is_null($list) or count($list)==0){
            pop_js('您没有该条学员档案的审核权限，如重复出现该问题，请联系分公司技术部！', 'self.parent.tb_remove();self.parent.location.reload();');
        }
        //dump($list);
        $this->assign($list);
        $this->display();
    }
    /**
     * 咨询师删除学员档案
     */
    public function zx_del_stuinfo(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,4);
        unset ($System);
        //学员id编号
        $stu_id=(integer) addslashes($_GET['id']);
        $Stuinfo=M('Stuinfo');
        $list=$Stuinfo->where("stu_id={$stu_id} and user_id={$_SESSION['user_id']} and shenhe='0' and tidang='0'")->find();
        
        if(is_null($list)){
            pop('您没有权限删除该条记录、该条记录已经通过审核！',U('ppts/manger_stuinfo'));
        }

        if($Stuinfo->delete($stu_id)){
            pop('该学生档案删除成功！',U('ppts/manger_stuinfo'));
        }else{
            pop('系统异常，删除操作未成功，请重新操作！',U('ppts/manger_stuinfo'));
        }
        unset ($Stuinfo);
        
    }

    /**
     * 咨询师学员档案提档
     *
     * @var integer $_GET['id']  需要提档的学员id
     */
    public function zx_stu_tidang(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,4);
        unset ($System);
        //学员id编号
        $stu_id=(integer) addslashes($_GET['id']);
        $Stuinfo=M('Stuinfo');
        $list=$Stuinfo->where("stu_id={$stu_id} and user_id={$_SESSION['user_id']}")->find();
        if(is_null($list)){
            pop('您无权提档该条信息，如有问题请联系技术部！', U('ppts/manger_stuinfo'));
        }
        if($Stuinfo->where("stu_id={$stu_id}")->setField('tidang','1')){
            $Stuinfo->where("stu_id={$stu_id}")->setField('td_time',get_date_full(time()));
            pop('提档成功！前台可继续进行相关的业务流程！', U('ppts/manger_stuinfo'));
        }
    }

    /**
     * 前台未录合同学员列表
     */
    public function qt_no_input_ht_stu(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32);
        unset ($System);

        
        $PPTS=D('Ppts');
        //$userid_str=$PPTS->get_bm_all_user($_SESSION['user_id'],'s');
        //获取该用户的校区部门id
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset ($PPTS);

        $M=M();
        //获取未录合同学员信息
        /**
         * 几大条件为：
         * 1.前台所属校区学员
         * 2.咨询师已经提档
         * 3.已经录入合同数为0
         */
        $sql="select t.stu_id,t1.stu_name,t1.stu_sex,t1.td_time "
        ."from lfy_stu_xiaoqu as t "
        ."left join lfy_stuinfo as t1 "
        ."on t.stu_id=t1.stu_id "
        ."where t1.tidang='1' and t.xq_id={$xq_id} "
        ."and ifnull((select count(ht_id) from lfy_stu_hetong where stu_id=t.stu_id),0)=0";
        $list=$M->query($sql);
        //dump($list);
        unset ($M);
        
        $this->assign('list', $list);
        $this->display();
    }

    /**
     * 前台退档功能
     * 前台对咨询师提档的学员基本信息进行退档操作
     * @var integer $id 学生id号
     */
    public function qt_no_input_htstu_tuidang(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32);
        unset ($System);

        
        $stu_id=(integer)addslashes($_GET['id']);

        $PPTS=D('Ppts');
        //$userid_str=$PPTS->get_bm_all_user($_SESSION['user_id'],'s');
        //获取该用户的校区部门id
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset ($PPTS);

        
        $sql="select count(t.stu_id) from lfy_stuinfo as t left join (lfy_stu_xiaoqu as t1) on (t.stu_id=t1.stu_id) where t1.xq_id={$xq_id} and t.stu_id={$stu_id}";
        $M=M();
        if(count($M->query($sql))==0){
            unset($M);
            pop('该学员提档信息不存在，或者你无权对该学员进行退档操作！', U('ppts/qt_no_input_ht_stu'));
        }

        $Stuinfo=M('Stuinfo');
        if($Stuinfo->where("stu_id={$stu_id}")->setField("tidang","0")){
            unset($Stuinfo);
            pop('对该学员退档操作成功！', U('ppts/qt_no_input_ht_stu'));
        }else{
            unset($Stuinfo);
            pop('系统错误，请刷新后重新尝试操作！', U('ppts/qt_no_input_ht_stu'));
        }
        
    }

    /**
     * 前台录入合同界面
     *
     * @var integer $_GET['id'] 需要录入学员档案的学员id
     */
    public function qt_input_hetong(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32);
        unset ($System);
        //学员id编号
        $stu_id=(integer) addslashes($_GET['id']);
        
        //建立PPTS数据处理模型
        $PPTS=D('Ppts');
        
        //进行获取用户所在的校区部门id号码
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        
        $fgs_id=$PPTS->get_user_bmid($_SESSION['user_id'],'k');
        //将校区id赋值到模板
        $this->assign('xq_id',$xq_id);
        //将分公司的部门id赋值到模板
        $this->assign('fgs_id', $fgs_id);
        //dump($fgs_id);
        //
        //将该用户分公司的所有校区输出到模板
        $this->assign('xq_list',$PPTS->get_fgs_xq_list($fgs_id));

        unset($PPTS);
        
        

        $Stuinfo=D('Stuinfo');
        $list=$Stuinfo->where("lfy_stuinfo.stu_id={$stu_id} and t.xq_id={$xq_id}")->join("lfy_stu_xiaoqu as t on t.stu_id=lfy_stuinfo.stu_id")->find();
        if(is_null($list)){
            unset($Stuinfo);
            pop('您无权对该学员录入学员档案！如有问题请联系技术部！', U('ppts/qt_no_input_ht_stu'));
        }

        //获取学员基本信息中的建档基本信息
        $this->assign($Stuinfo->get_jiandang($stu_id));

        unset ($Stuinfo);  //销毁学生信息对象

        $KP=M('Kecheng_price');  //建立课程价格模型
        $kp_list=$KP->where("kp_bmid={$fgs_id}")->field('distinct kp_name')->select();
        unset ($KP);  //销毁
        //将不重复的价格年级（名称）赋值到模板
        $this->assign('kpname_list', $kp_list);

        
        //将学员信息赋值到模板
        $this->assign($list);
        
        $this->display();
    }
    /**
     * 功能：各年级课程价格设置
     * 操作权限组：技术管理
     * 设置类型：总公司设置分公司
     * 范围：各年级
     */
    public function config_kecheng_jiage(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,128);
        unset ($System);

        $Kp=M('Kecheng_price');
        $kp_list=$Kp->order('kp_name,kp_num')->select();
        unset ($Kp);
        
        $this->assign('kp_list', $kp_list);

        $this->display();
    }

    /**
     * 保存分公司学员资料审核
     */
    public function fgs_stuinfo_shenhe_save(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,16);
        unset ($System);
        $stu_id=(integer) addslashes($_GET['id']);

        

        $Stuinfo=M('Stuinfo');
        $list=$Stuinfo->where("stu_id={$stu_id} and shenhe='0'")->find();

        if(is_null($list)){
            pop_js('该条记录已经通过审核，无需再次审核！', 'self.parent.tb_remove();self.parent.location.reload();');
        }
        unset ($list);


        //建立PPTS数据处理模型
        $PPTS=D('Ppts');
        $userid_str=$PPTS->get_bm_all_user($_SESSION['user_id'],'k');

        unset ($PPTS);
        $list=$Stuinfo->where("(0 {$userid_str}) and stu_id={$stu_id} and shenhe='0'")->find();
        
        if(is_null($list) or count($list)==0){
            pop_js('您没有该条学员档案的审核权限，如重复出现该问题，请联系公司技术部！', 'self.parent.tb_remove();self.parent.location.reload();');
        }

        if($Stuinfo->where("stu_id={$stu_id}")->setField('shenhe','1')){
            unset ($Stuinfo);
            pop_js('该学员档案审核成功！', 'self.parent.tb_remove();self.parent.location.reload();');
        }else{
            unset ($Stuinfo);
            pop_js('审核通过操作失败！请重新操作！', 'self.parent.tb_remove();self.parent.location.reload();');
        }

        

    }

    /**
     * 前台录入合同，获取价格数据
     * @var int $bm_id 分公司部门id
     * @var string $class_year 年级
     * @var int $class_kind 授课类型
     * @var int $gm_keshi 购买的课时数量
     * @return JSON
     */
    public function get_hetong_kecheng_jiage(){
        //权限检测
//        $System=D('System');
//        $System->check_qx_model($_SESSION['qx_id'],3,32);
//        unset ($System);
        //header('Content-Type:text/html;charset:gb2312');
        //获取前台传递的数据
        $bm_id=(integer)addslashes($_POST['bm_id']);
        //$class_year=addslashes($_GET['class_year']);
        $class_year=addslashes($_POST['class_year']);
        $class_kind=$_POST['class_kind'];
        $gm_keshi=(integer)addslashes($_POST['gm_keshi']);
        //echo $class_year;
        $KP=M('Kecheng_price');
        $info=$KP->where("kp_bmid={$bm_id} and kp_name='{$class_year}' and kp_num<{$gm_keshi}")->order('kp_price')->find();
        //dump($info);
        $old=$KP->where("kp_bmid={$bm_id} and kp_name='{$class_year}'")->order('kp_price desc')->find();
        if($class_kind=='11'){
            $data=array(
                'kp_price'=>$info['kp_price'],
                'kp_old'=>$old['kp_price']
            );
        }elseif($class_kind=='31'){
            $data=array(
                'kp_price'=>$info['kp_3a_price'],
                'kp_old'=>$old['kp_3a_price']
            );
        }elseif($class_kind=='12'){
            $data=array(
                'kp_price'=>round($info['kp_price']*0.75,0),
                'kp_old'=>round($old['kp_price']*0.75,0)
            );
        }else{
            $data=array(
                'kp_price'=>round($info['kp_3a_price']*0.75,0),
                'kp_old'=>round($old['kp_3a_price']*0.75,0)
            );
        }
        $str=json_encode($data);
        //dump($str);
        echo $str;
    }


    /**
     * 保存前台录入的学员电子合同
     *
     * @var $_POST前台录入数据数组
     */
    public function save_qt_input_hetong(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32);
        unset ($System);
        $stu_id=(integer) addslashes($_POST['stu_id']);
        $data['stu_id']=(integer) addslashes($_POST['stu_id']);
        $data['bm_id']=(integer)  addslashes($_POST['bm_id']);
        $data['ht_no']=addslashes($_POST['ht_no']);
        $data['create_kind']=addslashes($_POST['create_dangan_kind']);
        $data['create_price']=(integer)  addslashes($_POST['zonghe_fei']);
        $data['begin_date']=$_POST['begin_day'];
        $data['stop_date']=$_POST['stop_day'];
        $data['ht_user_id']=$_SESSION['user_id'];
        $data['xuefei_price']=(integer)  addslashes($_POST['sum_xuefei']);
        $data['hetong_price']=(integer)  addslashes($_POST['sum_hetong']);
        $data['beizhu']=$_POST['beizhu'];
        $data['ht_input_time']=get_date_full(time());
        $data['kecheng_fb']=$_POST['kecheng_fb'];
        //dump($data);
        $Stu_ht=M('Stu_hetong');
        //学员合同增加，返回插入的新学员合同流水id，如果失败则返回null
        $id=$Stu_ht->add($data);
        //销毁大数组和大对象
        unset ($data);
        unset ($Stu_ht);

        $New=M('Newht_info');
        for($i=1;$i<=8;$i++){
            if($_POST['gm_keshi_'.$i]>0){
                if($_POST['class_kind_'.$i]=='11')
                    $class_kind='普通一对一';
                elseif($_POST['class_kind_'.$i]=='31')
                    $class_kind='3A一对一';
                elseif($_POST['class_kind_'.$i]=='32')
                    $class_kind='3A一对多';
                elseif($_POST['class_kind_'.$i]=='12')
                    $class_kind='普通一对多';
                $n_data=array(
                    'hti_class'=>addslashes($_POST['class_year_'.$i]),
                    'hti_kind'=>$class_kind,
                    'hti_gmkeshi'=>(integer) addslashes($_POST['gm_keshi_'.$i]),
                    'hti_old_danjia'=>(integer) addslashes($_POST['old_price_'.$i]),
                    'hti_new_danjia'=>(integer) addslashes($_POST['sj_price_'.$i]),
                    'hti_sum_price'=>(integer) addslashes($_POST['gm_sum_'.$i]),
                    'hti_input_time'=>  get_date_full(time()),
                    'hti_userid'=>$_SESSION['user_id'],
                    'ht_id'=>$id
                );
                $New->add($n_data);
            }
        }
        unset ($New);
        //建立PPTS数据处理模型
        $PPTS=D('Ppts');
        //进行获取用户所在的校区部门id号码
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);


        //获取是否转校标识
        $zhuanxiao=(integer)addslashes($_POST['zhuanxiao']);
        //判断是否转校
        if($zhuanxiao==1){
            //获取转校目标
            $zx_xq_id=(integer)addslashes($_POST['zx_xq_id']);
            $data=array(
                'nz_old_xq_id'=>$xq_id,
                'nz_new_xq_id'=>$zx_xq_id,
                'nz_inputtime'=>get_date_full(time()),
                'nz_stu_id'=>$stu_id,
                'nz_ht_id'=>$id
            );
            //将学员转校相关信息写入学员新签转校信息表中
            $Stu_newqian_zhuanxiao=M('Stu_newqian_zhuanxiao');
            $Stu_newqian_zhuanxiao->add($data);
            unset($data);
            unset($Stu_newqian_zhuanxiao);
        }else{
            $data=array(
                'hx_stu_id'=>$stu_id,
                'hx_ht_id'=>$id,
                'hx_xq_id'=>$xq_id
            );
            //将不转校学员关联信息写入学员课时归属表中
            $Stu_ht_xiaoqu=M('Stu_ht_xiaoqu');
            $Stu_ht_xiaoqu->add($data);
            unset($data);
            unset($Stu_ht_xiaoqu);
        }

        //进行合同与咨询师对应关系处理
        $Stuinfo=M('Stuinfo');
        $ht_user_id=$Stuinfo->where("stu_id={$stu_id}")->getfield('user_id');
        unset($Stuinfo);
        $data=array(
            'zn_user_id'=>$ht_user_id,
            'zn_ht_id'=>$id
        );
        $Zx_newht=M('Zx_newht');
        $Zx_newht->add($data);
        unset($Zx_newht);
        
        
        //系统自动学员档案审核功能
        $Stuinfo=M("Stuinfo");
        $Stuinfo->where("stu_id={$stu_id}")->setField('shenhe','1');
        unset($Stuinfo);


        if($id){

            pop('学员电子合同录入成功！下一步操作请进入已录合同学员功能模块操作！', U('ppts/qt_ready_input_ht_stu'));
        }else{
            pop('系统异常错误，请刷新后重新进行操作！', U('ppts/qt_no_input_ht_stu'));
        }
    }


     /**
     * 前台已录合同学员列表
     */
    public function qt_ready_input_ht_stu(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32);
        unset ($System);

        //建立PPTS数据处理模型
        $PPTS=D('Ppts');
        //进行获取用户所在的校区部门id号码
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);
        //dump($xq_id);

        $M=M();
        $sql = "select t1.stu_id "
        ."from lfy_stuinfo as t1,lfy_stu_hetong as t2 "
        ."left join (lfy_stu_ht_xiaoqu as tt) on (tt.hx_ht_id=t2.ht_id) "
        ."where t1.tidang='1' "
        ."and ifnull("
        ."(select count(ht_id) from lfy_stu_hetong as n where n.stu_id=t1.stu_id),0)>0 "
        ."and t1.stu_id=t2.stu_id "
        ."and tt.hx_xq_id={$xq_id}";
        $list=$M->query($sql);
        unset($sql);
        import("ORG.Util.Page"); // 导入分页类
        $count=count($list);
        $Page=new Page($count,20); // 实例化分页类传入总记录数和每页显示的记录数
        $Page->setConfig('theme',"共计%totalRow%条记录 每页20条记录　当前%nowPage%/%totalPage% 页 %upPage% %downPage% %first%  %prePage%  <font color=red>%linkPage%</font>  %nextPage% %end%");
        $show=$Page->show(); // 分页显示输出
        $sql = "select t1.stu_id,stu_name,stu_sex,td_time,t2.ht_no,hetong_price,ht_input_time,t2.ht_id "
        ."from lfy_stuinfo as t1,lfy_stu_hetong as t2 "
        ."left join (lfy_stu_ht_xiaoqu as tt) on (tt.hx_ht_id=t2.ht_id) "
        ."where t1.tidang='1' "
        ."and ifnull("
        ."(select count(ht_id) from lfy_stu_hetong as n where n.stu_id=t1.stu_id),0)>0 "
        ."and t1.stu_id=t2.stu_id "
        ."and tt.hx_xq_id={$xq_id} "
        ."order by ht_input_time desc "
        ."limit {$Page->firstRow},{$Page->listRows}";
        $list=$M->query($sql);
        $this->assign('page', $show);
        unset($Page);
        unset($sql);
        //dump($list);
        unset ($M);


        //以下为计算合同的收款信息
        $SK=M('Qt_htshoukuan');
        $Hetong_keshi=M('Hetong_keshi');
        $Newht_info=M('Newht_info');
        
        foreach($list as $info=>$key){
            //dump($key['ht_id']);
            $sum=$SK->field('sum(sk_price) as ready_price')->where("ht_id={$key['ht_id']}")->select();
            //dump($sum);
            if(is_null($sum['0']['ready_price']))
                $sum['0']['ready_price']=0;
            $list[$info]['ready_price']=$sum['0']['ready_price'];
            
            //$ready_keshi 该合同已经购买的课时
            $ready_keshi=$Hetong_keshi->where("ht_id={$key['ht_id']}")->field('ifnull(sum(hk_num),0) as ready_keshi')->find();
            //合同的课时
            $hetong_keshi=$Newht_info->where("ht_id={$key['ht_id']}")->field('ifnull(sum(hti_gmkeshi),0) as hetong_keshi')->find();
            
            //合同剩余未购买课时
            $list[$info]['keshi']=$hetong_keshi['hetong_keshi']-$ready_keshi['ready_keshi'];
            
        }
        
        unset($SK);
        unset($Hetong_keshi);
        unset($Newht_info);
        
        //dump($list);
        //dump($list);
        $this->assign('list', $list);
        $this->display();
    }


    /**
     * 前台进行首次合同收款界面
     * @var integer $_GET['id'] 学员学号id
     */
    public function qt_hetong_shoukuan(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32);
        unset ($System);
        //获取学员id
        $stu_id=(integer) addslashes($_GET['id']);
        $this->assign('stu_id', $stu_id);
        
        //获取所属合同id
        $ht_id=(integer) addslashes($_GET['k_id']);
        $this->assign('ht_id', $ht_id);

        $Stu=M('Stuinfo');
        //获取学员的姓名
        $stu_name=$Stu->where("stu_id={$stu_id}")->getfield('stu_name');
        unset ($Stu);
        $this->assign('stu_name', $stu_name);
        $this->display();
    }

    /**
     * 保存前台合同收款处理方法
     * @var array $_POST 信息超级数组
     */
    public function save_qt_hetong_sk(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32);
        unset ($System);
       $M=M('Qt_htshoukuan');
       $M->create();
       $M->sk_input_time=get_date_full(time());
       $M->sk_input_userid=$_SESSION['user_id'];

       if($M->add()){
           pop_js('收款成功!!', 'self.parent.tb_remove();self.parent.location.reload();');
       }else{
           pop_js('收款失败，请重新进行操作!','self.parent.tb_remove();self.parent.location.reload();');
       }
    }


    /**
     * 前台查看已录合同信息   包含收款详细以及购买课时等信息
     *
     * @var integer $_GET['id']  合同ht_id号
     */
    public function qt_view_ready_inputht_info(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32);
        unset ($System);
        $ht_id=(integer)  addslashes($_GET['id']);

        $Stu_ht=D('Stu_hetong');

        //调用学员合同模块获取合同中的学员id
        $stu_id=$Stu_ht->get_stuid($ht_id);
        $ht_info=$Stu_ht->where("ht_id={$ht_id}")->find();
        if(is_null($ht_info)){
            pop('该合同信息不存在，请刷新后重新查看合同信息；如果问题一直存在，请联系公司技术部！',U('ppts/qt_ready_input_ht_stu'));
        }
        $this->assign($ht_info);
        unset($Stu_ht);

        $Stuinfo=D('Stuinfo');
        $stu_info=$Stuinfo->where("stu_id={$stu_id}")->find();
        if(is_null($stu_info)){
            pop('该合同不存在学员信息！请检查合同，如有问题请联系技术部处理！', U('ppts/qt_view_ready_inputht_info'));
        }
        $this->assign($stu_info);
        //获取学员基本信息中的建档基本信息
        $this->assign($Stuinfo->get_jiandang($stu_id));
        unset($Stuinfo);

        //获取合同各年级课时信息并赋值到模板
        $Newht=M('Newht_info');
        $this->assign('class_info', $Newht->where("ht_id={$ht_id}")->order('hti_id')->select());
        unset ($Newht);

        //获取收款信息并赋值到模板
        $SK=M('Qt_htshoukuan');
        //dump($SK->where("ht_id={$ht_id} and lfy_user.user_id=lfy_qt_htshoukuan.sk_input_userid")->table('lfy_user,lfy_qt_htshoukuan')->order('sk_input_time desc')->select());
        $this->assign('shoukuan_info', $SK->where("ht_id={$ht_id} and lfy_user.user_id=lfy_qt_htshoukuan.sk_input_userid")
        ->table('lfy_user,lfy_qt_htshoukuan')
        ->field('user_zsname,lfy_qt_htshoukuan.sk_input_userid,sk_id,sk_kind,sj_no,yh_no,sk_price,sk_yongtu,sk_beizhu,sk_input_time,shenhe')
        ->order('sk_input_time desc')
        ->select());

        unset ($SK);
        
        $this->display();
    }

    /**
     * 前台查看合同信息中的获取收款明细
     *
     * @param integer $_GET['ht_id'] 合同id号
     */
    public function get_qt_shoukuan_list(){
        //权限检测
//        $System=D('System');
//        $System->check_qx_model($_SESSION['qx_id'],3,32);
//        unset ($System);
        $ht_id=(integer) addslashes($_GET['ht_id']);
        //获取收款信息并赋值到模板
        $SK=M('Qt_htshoukuan');
        //dump($SK->where("ht_id={$ht_id} and lfy_user.user_id=lfy_qt_htshoukuan.sk_input_userid")->table('lfy_user,lfy_qt_htshoukuan')->order('sk_input_time desc')->select());
        $list=$SK->where("ht_id={$ht_id} and lfy_user.user_id=lfy_qt_htshoukuan.sk_input_userid")
        ->table('lfy_user,lfy_qt_htshoukuan')
        ->field('user_zsname,lfy_qt_htshoukuan.sk_input_userid,sk_id,sk_kind,sj_no,yh_no,sk_price,sk_yongtu,sk_beizhu,sk_input_time,shenhe')
        ->order('sk_input_time desc')
        ->select();

         unset ($SK);

         //dump($list);

         $str=json_encode($list);
         echo $str;
         unset ($list);
    }
    /**
     * 前台对合同详细中的收款进行删除操作
     *
     * @var integer $_POST['sk_id']  收款编号
     */
    public function qt_hetong_delshoukuan(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32);
        unset ($System);
        //如果检测到是非Ajax请求
        if(!$this->isAjax()){
            $this->ajaxReturn(10);
            exit();
        }
        
        $sk_id=(integer)  addslashes($_POST['sk_id']);
         //收款模型
        $SK=M('Qt_htshoukuan');
        $shenhe=$SK->where("sk_id={$sk_id}")->field('shenhe,sk_input_userid')->find();
        if(is_null($shenhe)){
            $this->ajaxReturn(0);  //该条收款信息不存在
            exit();
        }
        if($shenhe['shenhe']!=0){
            $this->ajaxReturn(1);  //该条信息已经通过审核，不允许删除
            exit();
        }
        if($shenhe['sk_input_userid']!=$_SESSION['user_id']){
            $this->ajaxReturn(3);  //不是当前用户，无法删除
            exit();
        }
        if($SK->delete($sk_id)){
            $this->ajaxReturn(2);  //删除成功！
            exit();
        }
        $this->ajaxReturn(10);  //删除失败
    }


    /**
     * 教务签约学员管理界面  操作人员：教务
     *
     * 权限组：3  权限值：256
     */
    public function jw_qianyue_stu_manger(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,256);
        unset ($System);

        $PPTS=D('Ppts');
        //获取校区部门id
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset ($PPTS);

        $sql = "select a.stu_id,a.stu_name,a.stu_sex,ht_input_time,c.ht_id,(select sum(sk_price) from lfy_qt_htshoukuan where ht_id=c.ht_id) as price "
    . " from lfy_stuinfo as a,lfy_stu_xiaoqu as b,lfy_stu_hetong as c "
    . " where a.stu_id=c.stu_id and a.stu_id=b.stu_id and (select sum(sk_price) from lfy_qt_htshoukuan where ht_id=c.ht_id)>0"
    ." order by ht_input_time desc";
        $S=M();
        $list=$S->query($sql);
        unset ($S);
        $this->assign('list', $list);
        unset($list);

        $this->display();
    }

    /*
     * 教务录入课时单时通过学员id获取学员信息
     * @var integer $_GET['stu_id']学员id
     */
    public function get_jw_keshidan_stuinfo(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,2048);
        unset ($System);
        $stu_id=(integer) addslashes($_GET['stu_id']);
        $Stuinfo=M('Stuinfo');
        $list=$Stuinfo->where("stu_id={$stu_id}")->find();
        unset($Stuinfo);
        if(empty($list)){
            $this->ajaxReturn(0);
            exit();
        }
        $str=json_encode($list);
        unset($list);
        echo $str;
    }


    /*
     * 教务录入课时单时通过教师用户id获取教师信息
     * @var integer $_GET['tec_id']教师user_id
     */
    public function get_jw_keshidan_teacherinfo(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,2048);
        unset ($System);
        //获取教师工号，3位
        $user_no=addslashes($_GET['tec_id']);
        
        $U=D('Ppts');
        $user_id=$U->no_get_userid($user_no);
        if(empty($user_id)){
            $this->ajaxReturn(0);
            exit();
        }
        
        
        
        $User=M();
        $sql = "SELECT user_zsname,user_sex,sf_kind "
        ."FROM lfy_user as t1 "
        ."LEFT JOIN (lfy_user_shenfen as t2) ON (t1.user_id=t2.user_id) "
        ."where sf_kind='t' and t1.user_id={$user_id} limit 1";
        $list=$User->query($sql);
        //dump($list);
        unset($User);
        if(empty ($list)){
            $this->ajaxReturn(0);
            exit();
        }
        $str=json_encode($list[0]);
        unset($list);
        echo $str;
    }

    /**
     * 教务课时单录入界面功能
     */
    public function jw_input_keshidan(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,2048);
        unset ($System);
        //建立PPTS数据处理模型
        $PPTS=D('Ppts');
        
        //进行获取用户所在的分公司部门id号码
        $fgs_id=$PPTS->get_user_bmid($_SESSION['user_id'],'k');
        //获取用户所在校区id
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset ($PPTS);

        $KP=M('Kecheng_price');  //建立课程价格模型
        $kp_list=$KP->where("kp_bmid={$fgs_id}")->field('distinct kp_name')->select();
        unset ($KP);  //销毁
        //将不重复的价格年级（名称）赋值到模板
        $this->assign('kpname_list', $kp_list);

        $this->display();
    }


    /**
     * 前台电子合同购买课时界面控制器
     * @var integer $_GET['id'] 学员id
     * @var integer $_GET['k_id'] 合同ht_id
     */
    public function qt_hetong_goumaikeshi(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32);
        unset ($System);

        //获取所属合同id
        $ht_id=(integer) addslashes($_GET['k_id']);
        $this->assign('ht_id', $ht_id);

        
        

        $SQL=M();
        $sql = "select t2.hti_class as year_kind,t2.hti_kind as sk_kind,t2.hti_gmkeshi as gm_keshi from lfy_newht_info as t2 where ht_id={$ht_id}";
        $list=$SQL->query($sql);
//        //过滤重复课时的购买情况
//        for($i=0;$i<count($list);$i++){
//            for($m=$i+1;$m<count($list);$m++){
//                if($list[$i]['year_kind']==$list[$m]['year_kind'] || $list[$i]['sk_kind']==$list[$m]['sk_kind']){
//                    $list[$i]['gm_keshi']+=$list[$m]['gm_keshi'];
//                    unset($list[$m]);
//                }
//            }
//        }
        //dump($list);
        //echo count($list);


//        foreach($list as $info=>$key){
//            //dump($key['ht_id']);
//
//            $huaizhang=$ZD->where("hd_stu_id={$key['stu_id']}")->count();
//            $list[$info]['huaizhang']=$huaizhang;
//        }


        foreach($list as $info=>$key){
            $gm_sql="select sum(hk_num) as gm_num from lfy_hetong_keshi as t1 where t1.hk_sk_kind='".$key['sk_kind']."' and t1.hk_kind='".$key['year_kind']."' and ht_id={$ht_id}";
            //获取已购买课时数量
            $gm_list=$SQL->query($gm_sql);
            //检测是否为null值
            if(is_null($gm_list[0]['gm_num'])){
                //如果为null则已经购买的为0
                $num=0;
            }else{
                //等于当前已经购买值
                $num=$gm_list[0]['gm_num'];
            }
            
            //计算剩余未购买课时
            $list[$info]['gm_keshi']=$key['gm_keshi']-$num;
        }
        //dump($list);
        $this->assign('sy_keshi_list', $list);



        //获取学员id
        $stu_id=(integer) addslashes($_GET['id']);
        $this->assign('stu_id', $stu_id);

        

        $Stu=M('Stuinfo');
        //获取学员的姓名
        $stu_name=$Stu->where("stu_id={$stu_id}")->getfield('stu_name');
        unset ($Stu);
        $this->assign('stu_name', $stu_name);

        //建立PPTS数据处理模型
        $PPTS=D('Ppts');

        //进行获取用户所在的分公司部门id号码
        $fgs_id=$PPTS->get_user_bmid($_SESSION['user_id'],'k');
        //获取用户所在校区id
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset ($PPTS);

        $KP=M('Kecheng_price');  //建立课程价格模型
        $kp_list=$KP->where("kp_bmid={$fgs_id}")->field('distinct kp_name')->select();
        unset ($KP);  //销毁
        //将不重复的价格年级（名称）赋值到模板
        $this->assign('kpname_list', $kp_list);


        

        $this->display();
    }

    /**
     * 前台已录入合同购买课时保存操作控制器
     *
     * @var array $_POST  课程购买相关数据数组
     */
    public function save_qt_goumaikeshi(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32);
        unset ($System);
        $stu_id=(integer)  addslashes($_POST['stu_id']);
        $ht_id=(integer) addslashes($_POST['ht_id']);

        //建立PPTS数据处理模型
        $PPTS=D('Ppts');
        //获取用户所在校区id
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset ($PPTS);

        
        $data=array(
            'hk_kind'=>  addslashes($_POST['year_kind']),
            'ht_id'=>$ht_id,
            'hk_kemu'=>  addslashes($_POST['kecheng_kind']),
            'hk_sk_kind'=>  addslashes($_POST['shouke_kind']),
            'hk_num'=>(integer)addslashes($_POST['keshi_num']),
            'input_userid'=>$_SESSION['user_id'],
            'input_time'=>  get_date_full(time()),
            'stu_id'=>$stu_id,
            'hk_xqid'=>$xq_id
        );

        $HK=M('Hetong_keshi');
        $HK->add($data);
        unset($HK);

        $SK=M('Stu_keshi');
        $data_k=array(
            'sks_kemu'=>addslashes($_POST['kecheng_kind']),
            'sks_kind'=>addslashes($_POST['year_kind']),
            'sks_sk_kind'=>addslashes($_POST['shouke_kind']),
            'sks_num'=>(integer)addslashes($_POST['keshi_num']),
            'input_userid'=>$_SESSION['user_id'],
            'input_time'=>  get_date_full(time()),
            'stu_id'=>$stu_id,
            'sks_xqid'=>$xq_id
        );
        $check=$SK->add($data_k);
        unset($SK);


        if($check){
            pop_js('购买课时操作成功！', 'self.parent.tb_remove();self.parent.location.reload();');
        }else{
            pop_js('未知错误，购买课时操作失败！请返回后重新操作', 'self.parent.tb_remove();self.parent.location.reload();');
        }
    }




    /**
     * 对前台购买课时的信息进行检测控制器
     */
    public function qt_hetong_gmks_check(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32);
        unset ($System);
        $year_kind=addslashes($_POST['year_kind']);
        $sk_kind=addslashes($_POST['sk_kind']);
        $ht_id=(integer)  addslashes($_POST['ht_id']);
        $gm_keshi=(integer) addslashes($_POST['gm_keshi']);


        if($gm_keshi==0){
            $this->ajaxReturn(3);
            //所购买的课时数量为0
            exit();
        }

        $SQL=M();
        $sql = "select t2.hti_class as year_kind,t2.hti_kind as sk_kind,t2.hti_gmkeshi as gm_keshi from lfy_newht_info as t2 where ht_id={$ht_id} and hti_class='{$year_kind}' and hti_kind='{$sk_kind}'";
        $list=$SQL->query($sql);

        $gm_sql="select sum(hk_num) as gm_num from lfy_hetong_keshi as t1 where t1.hk_sk_kind='".$list[0]['sk_kind']."' and t1.hk_kind='".$list[0]['year_kind']."' and ht_id={$ht_id}";
        //获取已购买课时数量
        $gm_list=$SQL->query($gm_sql);
        //检测是否为null值
        if(is_null($gm_list[0]['gm_num'])){
            //如果为null则已经购买的为0
            $num=0;
        }else{
            //等于当前已经购买值
            $num=$gm_list[0]['gm_num'];
        }
        //计算剩余未购买课时
        $list[0]['gm_keshi']=$list[0]['gm_keshi']-$num;
        if($list[0]['gm_keshi']==0){
            $this->ajaxReturn(1);  //剩余课时为0
            exit();
        }
        if($list[0]['gm_keshi']<$gm_keshi){
            $this->ajaxReturn(0);  //剩余课时数不够
            exit();
        }

        $this->ajaxReturn(10);  //正常购买
    }

    /**
     * 教务查看签约学员合同详细信息
     * @var integer $_GET['id'] 合同编号
     */
    public function jw_view_qianyue_hetong(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,256);
        unset ($System);

        $ht_id=(integer)  addslashes($_GET['id']);

        $Stu_ht=D('Stu_hetong');

        //调用学员合同模块获取合同中的学员id
        $stu_id=$Stu_ht->get_stuid($ht_id);
        $ht_info=$Stu_ht->where("ht_id={$ht_id}")->find();
        if(is_null($ht_info)){
            pop('该合同信息不存在，请刷新后重新查看合同信息；如果问题一直存在，请联系公司技术部！',U('ppts/qt_ready_input_ht_stu'));
        }
        $this->assign($ht_info);
        unset($Stu_ht);


        $Stuinfo=D('Stuinfo');
        $stu_info=$Stuinfo->where("stu_id={$stu_id}")->find();
        if(is_null($stu_info)){
            pop('该合同不存在学员信息！请检查合同，如有问题请联系技术部处理！', U('ppts/qt_view_ready_inputht_info'));
        }
        $this->assign($stu_info);
        //获取学员基本信息中的建档基本信息
        $this->assign($Stuinfo->get_jiandang($stu_id));
        unset($Stuinfo);
        
        $this->display();
    }

    /**
     * 教务录入课时单时对相关信息进行检测，ajax返回数据
     * @var integer $_GET['stu_id'] 学员id
     * @var string $_GET['year_kind'] 年级类型(价格类型)
     * @var string $_GET['shouke_kind'] 授课类型
     * @var string $_GET['shouke_kemu'] 授课科目
     * @var float $_GET['keshi'] 消耗的课时数量
     */
    public function jw_input_keshidan_check(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,2048);
        unset ($System);
        
        $stu_id=(integer)addslashes($_POST['stu_id']);
        $year_kind=addslashes($_POST['year_kind']);
        $shouke_kind=addslashes($_POST['shouke_kind']);
        $shouke_kemu=addslashes($_POST['shouke_kemu']);
        $keshi=$_POST['keshi'];

//        $stu_id=(integer)addslashes($_GET['stu_id']);
//        $year_kind=addslashes($_GET['year_kind']);
//        $shouke_kind=addslashes($_GET['shouke_kind']);
//        $shouke_kemu=addslashes($_GET['shouke_kemu']);
//        $keshi=$_GET['keshi'];

        if($stu_id==''){
            //学员id不能为空
            $this->ajaxReturn(0);
            exit();
        }
        if($keshi<=0){
            //消耗的课时小于0
            $this->ajaxReturn(1);
            exit();
        }

        //以下为计算指定年级类型，授课类型，科目，学员的剩余课时情况
        $SQ=M();
        $sql="select sum(sks_num) as gm_keshi "
        ."from lfy_stu_keshi as t "
        ."where sks_kemu='{$shouke_kemu}' and sks_kind='{$year_kind}' and sks_sk_kind='{$shouke_kind}' and stu_id={$stu_id}";
        $sy_info=$SQ->query($sql);
        if(is_null($sy_info[0]['gm_keshi'])){
            //如果学生课时不存在
            $this->ajaxReturn(2);
            exit ();
        }
        //学员购买课时数量
        $gm_keshi=$sy_info[0]['gm_keshi'];
        unset($sy_info);
        //dump($gm_keshi);


        
        $sql="select sum(jks_num) as xh_keshi "
        ."from lfy_jiaowu_keshixh "
        ."where jks_kemu='{$shouke_kemu}' and jks_kind='{$year_kind}' and jks_sk_kind='{$shouke_kind}' and stu_id={$stu_id}";
        $xh_info=$SQ->query($sql);
        unset($SQ);
        //$this->ajaxReturn(11, dump($xh_info));
        //dump($xh_info);
        
        if(is_null($xh_info[0]['xh_keshi'])){
            $xh_num=0;
        }else{
            $xh_num=$xh_info[0]['xh_keshi'];
        }

        //dump($xh_num);
        

        $num=$gm_keshi-$xh_num;
        

        if($num<0){
            //课时数不足
            $this->ajaxReturn(3);
            exit();
        }
        if($num==0){
             //剩余课时数为0，不能在录入课时
            $this->ajaxReturn(4);
            exit();
        }
       if(($num-$keshi)>=0){
           //可以录入
            $this->ajaxReturn(55);
            exit();
       }else{
           //剩余课时不足，不能录入该次课时
            $this->ajaxReturn(22);
            exit();
       }

        //异常错误
        $this->ajaxReturn(88);
        
    }


    /**
     * 保存教务录入的课时单
     *
     * @var array $_POST 课时单相关信息数组
     */
    public function save_jw_input_keshidan(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,2048);
        unset ($System);
         //建立PPTS数据处理模型
        $PPTS=D('Ppts');
        //获取用户所在校区id
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        $teacher_id=$PPTS->no_get_userid(addslashes($_POST['teacher_id']));
        if(empty($teacher_id)){
            pop('课时单录入错误，请返回后尝试重新录入；如果问题一直存在，请联系公司技术部！',U('ppts/jw_input_keshidan'));
            exit();
        }
        unset ($PPTS);
        
        
        $data=array(
            'stu_id'=>(integer)addslashes($_POST['stu_id']),
            'teacher_userid'=>$teacher_id,
            'jks_num'=>$_POST['keshi'],
            'ksd_no'=>$_POST['ksd_no'],
            'input_userid'=>$_SESSION['user_id'],
            'input_time'=>  get_date_full(time()),
            'jks_kind'=>  addslashes($_POST['year_kind']),
            'jks_sk_kind'=>  addslashes($_POST['shouke_kind']),
            'jks_kemu'=>  addslashes($_POST['shouke_kemu']),
            'sk_begin'=>$_POST['riqi'].' '.$_POST['b_begin'],
            'sk_stop'=>$_POST['riqi'].' '.$_POST['b_stop'],
            'xq_id'=>$xq_id,
            'kind'=>addslashes($_POST['kind'])
        );
        $JK=M('Jiaowu_keshixh');
        if($JK->add($data)){
            pop('课时单录入成功，将自动返回到课时单录入界面！',U('ppts/jw_input_keshidan'));
        }else{
            pop('课时单录入错误，请返回后尝试重新录入；如果问题一直存在，请联系公司技术部！',U('ppts/jw_input_keshidan'));
        }
    }
    
    /**
     * 分公司数据统计功能
     */
    public function fgs_data_tongji(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,4096);
        unset ($System);
        
        //建立一个执行SQL的数据模型
        $SQL = M();
        
        $now_date=get_year_month(time());
        
        //dump($now_date);

        //各校区新签人数，签约额，新签实收数据获取开始
        //$sql = "select count(t1.stu_id) as num,bm_name as name from lfy_stu_hetong as t1 left join (lfy_stu_xiaoqu as t2,lfy_bumen as t3) on (t1.stu_id=t2.stu_id and t3.bm_id=t2.xq_id) where left(ht_input_time,7)='2011-04' group by t2.xq_id order by num desc limit 3";
        $sql = "select "
            ."(select count(t2.stu_id) "
            ."from lfy_stu_hetong as t2,lfy_stu_xiaoqu as t3 "
            ."where t2.stu_id=t3.stu_id and t3.xq_id=t1.bm_id and left(t2.ht_input_time,7)='{$now_date}') as num,"
            ."ifnull("
            ."(select sum(t2.hetong_price) from "
            ."lfy_stu_hetong as t2,lfy_stu_xiaoqu as t3 "
            ."where t2.stu_id=t3.stu_id and t3.xq_id=t1.bm_id and left(t2.ht_input_time,7)='{$now_date}'),0) "
            ."as qianyuee,"
            ."ifnull("
            ."(select sum(t2.sk_price) "
            ."from lfy_qt_htshoukuan as t2,lfy_stu_xiaoqu as t3 "
            ."where t2.stu_id=t3.stu_id and t3.xq_id=t1.bm_id and left(t2.sk_input_time,7)='{$now_date}'),0) as new_shishou,"
            ."t1.bm_name as name "
        ."from lfy_bumen as t1 where t1.bm_kind='s' order by num desc,t1.bm_name limit 3";
        $list = $SQL->query($sql);
        //dump($list);
        
        //dump($list);
        $this->assign('list', $list);
        unset ($list);
        //各校区新签人数，签约额，新签实收数据获取结束
        
        unset($SQL);
 
        $this->display();
    }
    
    /**
     * 教务课时单管理功能
     */
    public function jw_keshidan_manger(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,8192);
        unset ($System);
        //录入起止时间
        $input_begin_date=$_GET['input_begin_date'];
        $this->assign('input_begin_date',$input_begin_date);
        $input_stop_date=$_GET['input_stop_date'];
        $this->assign('input_stop_date',$input_stop_date);
        //授课起止时间
        $sk_begin_date=$_GET['sk_begin_date'];
        $this->assign('sk_begin_date',$sk_begin_date);
        $sk_stop_date=$_GET['sk_stop_date'];
        $this->assign('sk_stop_date',$sk_stop_date);

        //获取上课状态
        $shangke_kind=$_GET['shangke_kind'];
        $this->assign('shangke_kind',$shangke_kind);

        //获取授课类型
        $shouke_kind=$_GET['shouke_kind'];
        $this->assign('shouke_kind', $shouke_kind);

        //获取科目信息
        $kemu=$_GET['kemu'];
        $this->assign('kemu', $kemu);

        
//        $Keshidan=M('Jiaowu_keshixh');
//        $list=$Keshidan->where("input_userid={$_SESSION['user_id']}")->select();
//        dump($list);
        $sql = "SELECT t.jks_id as id,t.stu_id,t1.stu_name,t.jks_kind as year_kind,"
                ."t.jks_sk_kind as sk_kind,t.jks_kemu as kemu,t.sk_begin,t.sk_stop,t2.user_zsname as name,t.jks_num as xh_keshi,t.kind,t.y_shenhe as shenhe "
        ."FROM lfy_jiaowu_keshixh as t "
        ."left join (lfy_stuinfo as t1,lfy_user as t2) "
            ."on (t.stu_id=t1.stu_id and t.teacher_userid=t2.user_id) "
        ."where input_userid={$_SESSION['user_id']} order by t.sk_begin";
        $SQL=M();
        $list=$SQL->query($sql);
        
        unset($SQL);
        //dump($list);
        
        $this->assign('list', $list);
        unset($list);
        
        $this->display();
    }
    
    /**
     * 分公司财务收款审核界面控制器
     */
    public function fgs_shoukuan_shenhe(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,16384);
        unset ($System);
        
        $this->display();
    }


    /**
     * 教务-课时单删除功能
     *
     * 对自己未通过审核的课时单进行删除操作
     */
    public function jw_keshidan_del(){
        $id=(integer)addslashes($_GET['id']);

        $SQL=M('Jiaowu_keshixh');
        //检查该条信息是否存在
        if($SQL->where("jks_id={$id} and input_userid={$_SESSION['user_id']}")->count()==0){
            unset($SQL);
            pop_js('该条记录信息不存在，如确定为系统问题，请联系技术部处理！', 'javascript:history.go(-1);');
        }

        $shenhe=$SQL->where("jks_id={$id} and input_userid={$_SESSION['user_id']}")->getField('y_shenhe');
        //对课时单的审核状态进行检测
        if($shenhe==0){
            if($SQL->where("jks_id={$id} and input_userid={$_SESSION['user_id']}")->delete()){
                unset($SQL);
                pop('该条课时单删除成功！',U('ppts/jw_keshidan_manger'));
            }else{
                unset($SQL);
                pop('系统未知错误，删除课时单失败，请返回后重新进行操作！',U('ppts/jw_keshidan_manger'));
            }
        }else{
            unset($SQL);
            pop('该课时单已经通过审核，您没有权限进行删除该课时单！',U('ppts/jw_keshidan_manger'));
        }
    }


    /**
     * 学管公共接档池逻辑程序
     */
//    public function xg_share_jiedangchi(){
//        //权限检测
//        $System=D('System');
//        $System->check_qx_model($_SESSION['qx_id'],3,512);
//        unset ($System);
//
//        //建立PPTS数据处理模型 并获取该用户所在的校区所有用户
//        $PPTS=D('Ppts');
//        $userid_str=$PPTS->get_bm_all_user($_SESSION['user_id'],'s');
//        unset ($PPTS);
//        //本校区学员过滤
//        //echo $userid_str;
//
//        $M=M();
//        $sql = "SELECT t.stu_id,t1.stu_name,t1.stu_sex "
//        ."FROM lfy_stu_hetong as t "
//        ."left join (lfy_stuinfo as t1) on (t.stu_id=t1.stu_id) "
//        ."where (select sum(sk_price) from lfy_qt_htshoukuan where ht_id=t.ht_id)=t.hetong_price "
//        ."and ifnull("
//        ."(select count(stu_id) from lfy_xueguan_jiedang as tt where tt.stu_id=t.stu_id),0)=0 "
//        ."and (0 {$userid_str})";
//        $list=$M->query($sql);
//        unset ($M);
//
//        $this->assign('list', $list);
//        $this->display();
//    }
    
    /**
     * 学管接档功能
     *
     * @param $_GET['id'] 接档学生的stu_id
     */
//    public function xg_jiedang(){
//        //权限检测
//        $System=D('System');
//        $System->check_qx_model($_SESSION['qx_id'],3,512);
//        unset ($System);
//
//        //获取学生stu_id值，并强制过滤和转换为数值
//        $stu_id=(integer)addslashes($_GET['id']);
//
//        //获取该学生已经被接档的数量
//        $Xueguan_jiedang=M('Xueguan_jiedang');
//        $count=$Xueguan_jiedang->where("stu_id={$stu_id}")->count();
//
//        if($count>0){
//            unset($Xueguan_jiedang);
//            pop('该学生已经有学管进行接档，如确认该学生需要您来接档，请联系进行调档！',U('ppts/xg_share_jiedang'));
//        }else{
//            $data=array(
//                'user_id'=>$_SESSION['user_id'],
//                'stu_id'=>$stu_id,
//                'xj_time'=>get_date_full(time())
//            );
//            if($Xueguan_jiedang->add($data)){
//                unset($Xueguan_jiedang);
//                pop('学习管理师接档成功！将自动跳转到[接档学员管理系统]',U('ppts/xg_jiedang_stu_manger'));
//            }else{
//                unset($Xueguan_jiedang);
//                pop('系统发生未知性错误，请返回后重新操作！',U('ppts/xg_share_jiedang'));
//            }
//        }
//    }

    /**
     * 学管接档学员管理
     * 自动筛选管理自己接档的学员
     *
     * 主要功能包括查看学员详细信息，显示合同到期时间，提醒进行续费   进行日常行为记录的录入  提请进行续费功能 提出退费申请
     */
    public function xg_jiedang_stu_manger(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,1024);
        unset ($System);
        $SQL=M();
        $sql="SELECT t.stu_id,t1.stu_no,t1.stu_name,t1.stu_sex,t.xj_time as time "
        ."FROM lfy_xueguan_jiedang as t "
        ."left join (lfy_stuinfo as t1) on (t.stu_id=t1.stu_id) "
        ."where t.user_id={$_SESSION['user_id']} "
        ."order by time desc";
        $list=$SQL->query($sql);
        unset($SQL);
        $this->assign('list', $list);
        unset($list);
        
        $this->display();
    }

    /**
     * 学管查看接档学员基本信息
     *
     * 
     */
    public function xg_view_stu_info(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,1024);
        unset ($System);
        $stu_id=(integer)addslashes($_GET['id']);
        //调用本类中的方法，进行检测是否为已经接档的学员
        $this->xg_check_jiedang($stu_id);


        $Stuinfo=M('Stuinfo');
        $list=$Stuinfo->where("stu_id={$stu_id}")->find();
        unset ($Stuinfo);
        if(is_null($list)){
            pop_js('该学员信息不存在！请联系技术部！','self.parent.tb_remove();self.parent.location.reload();');
        }
        $this->assign($list);
        unset ($list);

        $this->display();

    }

    /**
     * 学管检测是否具有该接档学员的权限
     *
     * @param integer $stu_id
     */
    private function xg_check_jiedang($stu_id){
        $Xueguan_jiedang=M('Xueguan_jiedang');
        $count=$Xueguan_jiedang->where("stu_id={$stu_id} and user_id={$_SESSION['user_id']}")->count();
        unset($Xueguan_jiedang);
        if($count==0){
            pop('对不起，您未接档该学员，没有权限进行该操作！',U('ppts/xg_jiedang_stu_manger'));
        }
    }


    /**
     * 学管查看学员评语信息功能
     */
    public function xg_view_stu_pingyu(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,1024);
        unset ($System);

        $stu_id=(integer)  addslashes($_GET['id']);

        $this->assign('stu_id', $stu_id);

        $this->xg_check_jiedang($stu_id);

        
        $Stuinfo=M('Stuinfo');
        $list=$Stuinfo->where("stu_id={$stu_id}")->find();
        unset ($Stuinfo);
        if(is_null($list)){
            pop_js('该学员信息不存在！请联系技术部！','self.parent.tb_remove();self.parent.location.reload();');
        }
        $this->assign($list);



        $Stu_pingyu=M('Stu_pingyu');
        $py_list=$Stu_pingyu->where("stu_id={$stu_id}")->join("lfy_user as u on u.user_id=lfy_stu_pingyu.user_id")->order("input_time")->select();
        unset($Stu_pingyu);

        $this->assign('py_list',$py_list);



        $this->display();
    }

    /**
     * 学管签写新学员评语功能界面
     * 进行学员检测
     */
    public function xg_add_stu_pingyu(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,1024);
        unset ($System);

        
        $stu_id=(integer)addslashes($_GET['id']);
        $this->assign('stu_id',$stu_id);

        $this->xg_check_jiedang($stu_id);

        $this->display();
    }

    /**
     * 学管保存对接档学员进行的评语操作
     */
    public function xg_save_add_stu_pingyu(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,1024);
        unset ($System);


        $stu_id=(integer)addslashes($_POST['stu_id']);
       
        $this->xg_check_jiedang($stu_id);

        $data=array(
            'stu_id'=>$stu_id,
            'user_id'=>$_SESSION['user_id'],
            'py_body'=>addslashes($_POST['py_body']),
            'input_time'=>get_date_full(time())
        );

        $Stu_pingyu=M('Stu_pingyu');
        if($Stu_pingyu->add($data)){
            unset($Stu_pingyu);
            pop_js('对学员进行的新评语保存成功！','self.parent.tb_remove();self.parent.location.reload();');
        }else{
            unset($Stu_pingyu);
            pop_js('系统未知错误，请重新进行评语添加操作！','self.parent.tb_remove();self.parent.location.reload();');
        }
    }


    /**
     * 学管查看咨询师首次签订的培训合同
     */
    public function xg_view_stu_first_hetong(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,1024);
        unset ($System);


        
        $stu_id=(integer)addslashes($_GET['id']);

        //进行检测该学管是否接档该学员
        $this->xg_check_jiedang($stu_id);

        $Stu_ht=D('Stu_hetong');

        //调用学员合同模块获取合同中的学员id
        //$stu_id=$Stu_ht->get_stuid($ht_id);
        $ht_info=$Stu_ht->where("stu_id={$stu_id}")->find();
        if(is_null($ht_info)){
            pop('该合同信息不存在，请刷新后重新查看合同信息；如果问题一直存在，请联系公司技术部！',U('ppts/xg_jiedang_stu_manger'));
        }
        $this->assign($ht_info);
        unset($Stu_ht);

        $Stuinfo=D('Stuinfo');
        $stu_info=$Stuinfo->where("stu_id={$stu_id}")->find();
        if(is_null($stu_info)){
            pop('该合同不存在学员信息！请检查合同，如有问题请联系技术部处理！', U('ppts/qt_view_ready_inputht_info'));
        }
        $this->assign($stu_info);
        //获取学员基本信息中的建档基本信息
        $this->assign($Stuinfo->get_jiandang($stu_id));
        unset($Stuinfo);

        //获取合同各年级课时信息并赋值到模板
        $Newht=M('Newht_info');
        $this->assign('class_info', $Newht->where("ht_id={$ht_info['ht_id']}")->order('hti_id')->select());
        unset ($Newht);

        $this->display();
    }


    /**
     * 校区热线上门情况录入界面控制器
     */
    public function qt_input_rexianshangmen(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,65536);
        unset ($System);
        $PPTS=D('Ppts');
        $fgs_id=$PPTS->get_user_bmid($_SESSION['user_id'],'k');
        unset($PPTS);
        $sql="select t.user_id,t2.user_zsname "
        ."from lfy_user_bumen as t "
        ."left join (lfy_user_shenfen as t1,lfy_user as t2) "
        ."on (t.user_id=t1.user_id and t.user_id=t2.user_id) "
        ."where t.bm_id={$fgs_id} and t1.sf_kind='z'";
        $S=M();
        $this->assign('zs_list',$S->query($sql));
        unset($S);
        $this->display();
    }


    /**
     * 保存校区热线上门情况录入的信息
     */
    public function qt_save_input_rexianshangmen(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,65536);
        unset ($System);
        $R=M('Rexian_shangmen_data');
        $R->create();

        $R->rs_input_userid=addslashes($_SESSION['user_id']);
        $R->rs_week=strftime('%W');
        $R->rs_time=time();
        $R->rs_input_time=get_date_full(time());
        $R->rs_come_time=str_replace('_', '-',addslashes($R->rs_come_time));
        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);
        $R->xq_id=$xq_id;

        if($R->add()){
            unset($R);
            pop('校区新热线上门情况添加成功！系统将自动返回到录入界面！', U('ppts/qt_input_rexianshangmen'));
        }else{
            unset($R);
            pop('系统未知错误，请刷新后重新录入！', U('ppts/qt_input_rexianshangmen'));
        }
         
         
     }

     /**
      * 校区热线上门情况管理-统计界面以及导航界面
      *
      * 角色：前台 校监
      */
     public function qt_rexianshangmen_manger(){
          //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,131072);
        unset ($System);

        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);
        
        $nowdate=get_date(time());
        //获取校区当天的上门数量
        $RE=M('Rexian_shangmen_data');
        $nowdate_shangmen_count=$RE->where("rs_kind='上门' and rs_come_time='{$nowdate}' and xq_id={$xq_id}")->count();
        if(is_null($nowdate_shangmen_count)){
            $nowdate_shangmen_count=0;
        }
        $this->assign('nowdate_shangmen_count', $nowdate_shangmen_count);
        //获取校区当天的上门约访数量
        $nowdate_shangmen_yuefang_count=$RE->where("rs_kind='上门' and rs_fang_kind='约访' and rs_come_time='{$nowdate}' and xq_id={$xq_id}")->count();
        if(is_null($nowdate_shangmen_yuefang_count)){
            $nowdate_shangmen_yuefang_count=0;
        }
        $this->assign('nowdate_shangmen_yuefang_count', $nowdate_shangmen_yuefang_count);

        //获取校区当天的上门直访数量
        $nowdate_shangmen_zhifang_count=$RE->where("rs_kind='上门' and rs_fang_kind='直访' and rs_come_time='{$nowdate}' and xq_id={$xq_id}")->count();
        if(is_null($nowdate_shangmen_zhifang_count)){
            $nowdate_shangmen_zhifang_count=0;
        }
        $this->assign('nowdate_shangmen_zhifang_count', $nowdate_shangmen_zhifang_count);

        //获取校区当天的热线数量
        $nowdate_rexian_count=$RE->where("rs_kind='热线' and rs_come_time='{$nowdate}' and xq_id={$xq_id}")->count();
        if(is_null($nowdate_rexian_count)){
            $nowdate_rexian_count=0;
        }
        $this->assign('nowdate_rexian_count', $nowdate_rexian_count);


        $nowmonth=date( 'Y-m', time());
        //获取校区当月的热线数量
        $nowmonth_rexian_count=$RE->where("rs_kind='热线' and xq_id={$xq_id} and (rs_come_time like '{$nowmonth}%')")->count();
        if(is_null($nowmonth_rexian_count)){
            $nowmonth_rexian_count=0;
        }
        $this->assign('nowmonth_rexian_count', $nowmonth_rexian_count);


        //获取校区当月的上门数量
        $nowmonth_shangmen_count=$RE->where("rs_kind='上门' and xq_id={$xq_id} and (rs_come_time like '{$nowmonth}%')")->count();
        //dump($RE->where("rs_kind='上门' and xq_id={$xq_id} and (rs_come_time like '{$nowmonth}%')")->select());
        if(is_null($nowmonth_shangmen_count)){
            $nowmonth_shangmen_count=0;
        }
        $this->assign('nowmonth_shangmen_count', $nowmonth_shangmen_count);

        //获取校区当月的上门约访数量
        $nowmonth_shangmen_yuefang_count=$RE->where("rs_kind='上门' and rs_fang_kind='约访' and xq_id={$xq_id} and (rs_come_time like '{$nowmonth}%')")->count();
        //dump($RE->where("rs_kind='上门' and xq_id={$xq_id} and (rs_come_time like '{$nowmonth}%')")->select());
        if(is_null($nowmonth_shangmen_yuefang_count)){
            $nowmonth_shangmen_yuefang_count=0;
        }
        $this->assign('nowmonth_shangmen_yuefang_count', $nowmonth_shangmen_yuefang_count);

        //获取校区当月的上门直访数量
        $nowmonth_shangmen_zhifang_count=$RE->where("rs_kind='上门' and rs_fang_kind='直访' and xq_id={$xq_id} and (rs_come_time like '{$nowmonth}%')")->count();
        //dump($RE->where("rs_kind='上门' and xq_id={$xq_id} and (rs_come_time like '{$nowmonth}%')")->select());
        if(is_null($nowmonth_shangmen_zhifang_count)){
            $nowmonth_shangmen_zhifang_count=0;
        }
        $this->assign('nowmonth_shangmen_zhifang_count', $nowmonth_shangmen_zhifang_count);
        
        unset($RE);
        $this->display();
     }

     /**
      * 校区热线上门情况管理-情况具体管理
      *
      * 角色：前台  校监
      */
     public function qt_rexianshangmen_sum_manger(){
         //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,131072);
        unset ($System);
        $kind=$_GET['kind'];
        if($kind=='shangmen'){
            $kind='qt_rexianshangmen_shangmen_manger';
            $str='上门';
        }else{
            $kind='qt_rexianshangmen_rexian_manger';
            $str='热线';
        }
        



        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);
        $RE=M('Rexian_shangmen_data');
        $begin_time=time()-(3600*24*30);
        //$list=$RE->where("rs_kind='上门' and rs_time>{$begin_time} and xq_id={$xq_id}")->join("lfy_user as t on t.user_id=lfy_rexian_shangmen_data.zss_user_id")->order('rs_come_time desc')->select();
        //dump($list);

        import("ORG.Util.Page"); // 导入分页类
        $count=$RE->where("rs_kind='{$str}' and rs_time>{$begin_time} and xq_id={$xq_id}")->join("lfy_user as t on t.user_id=lfy_rexian_shangmen_data.zss_user_id")->order('rs_come_time desc')->count();
        $Page=new Page($count,20); // 实例化分页类传入总记录数和每页显示的记录数
        $Page->setConfig('theme',"共计%totalRow%条记录 每页20条记录　当前%nowPage%/%totalPage% 页 %upPage% %downPage% %first%  %prePage%  <font color=red>%linkPage%</font>  %nextPage% %end%");
        $show=$Page->show(); // 分页显示输出
        $list=$RE->
        where("rs_kind='{$str}' and rs_time>{$begin_time} and xq_id={$xq_id}")
        ->field('rs_come_time,rs_qudao,rs_fang_kind,rs_laifang,rs_nowqianyue,rs_qianyue_jine,user_zsname,rs_stu_jiazhang,rs_stu_name,rs_id')
        ->join("lfy_user as t on t.user_id=lfy_rexian_shangmen_data.zss_user_id")
        ->order('rs_come_time desc')
        ->limit($Page->firstRow.','.$Page->listRows)
        ->select();
        unset($RE);
        $this->assign('list', $list);
        $this->assign('page',$show);
        unset($Page);
        unset($list);

        $this->display('ppts:'.$kind);
     }

     /**
      * 校区进行查看热线上门情况详细信息控制器
      */
     public function qt_view_rexianshangmen_info(){
         //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,131072);
        unset ($System);
         $kind=$_GET['kind'];
         if($kind=='shangmen'){
             $kind='qt_view_rexianshangmen_shangmen_info';
         }else{
             $kind='qt_view_rexianshangmen_rexian_info';
         }
        $rs_id=(integer)  addslashes($_GET['id']);
        $RE=M('Rexian_shangmen_data');
        $begin_time=time()-(3600*24*30);
        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);
        $list=$RE->where("rs_id={$rs_id} and xq_id={$xq_id} and rs_time>{$begin_time}")->field('rs_input_time,rs_time,rs_come_time,rs_qudao,rs_fang_kind,rs_laifang,rs_nowqianyue,rs_qianyue_jine,rs_shishou_jine,rs_stu_school,rs_stu_year,rs_stu_jiazhang,rs_tel,rs_stu_name,rs_xueke,rs_beizhu,t.user_zsname,t2.user_zsname as input_username')->join("lfy_user as t on t.user_id=lfy_rexian_shangmen_data.zss_user_id")->join("lfy_user as t2 on t2.user_id=lfy_rexian_shangmen_data.rs_input_userid")->find();
        //dump($list);
        if(is_null($list)){
            pop('该记录信息不存在或者您无权查看该条记录信息！',U('ppts/'.$kind));
        }
        $this->assign($list);
        unset($list);
        unset($RE);


         $this->display('ppts:'.$kind);
     }


     public function qt_edit_rexianshangmen_info(){
         //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,131072);
        unset ($System);
         $kind=$_GET['kind'];
         if($kind=='rexian'){
             $kind='qt_edit_rexianshangmen_rexian_info';
         }else{
             $kind='qt_edit_rexianshangmen_shangmen_info';
         }

         $PPTS=D('Ppts');
        $fgs_id=$PPTS->get_user_bmid($_SESSION['user_id'],'k');
        unset($PPTS);
        $sql="select t.user_id,t2.user_zsname "
        ."from lfy_user_bumen as t "
        ."left join (lfy_user_shenfen as t1,lfy_user as t2) "
        ."on (t.user_id=t1.user_id and t.user_id=t2.user_id) "
        ."where t.bm_id={$fgs_id} and t1.sf_kind='z'";
        $S=M();
        $this->assign('zs_list',$S->query($sql));
        unset($S);
         



        $rs_id=(integer)  addslashes($_GET['id']);
        $RE=M('Rexian_shangmen_data');
        $begin_time=time()-(3600*24*30);
        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);
        $list=$RE->where("rs_id={$rs_id} and xq_id={$xq_id} and rs_time>{$begin_time}")->field('rs_id,rs_input_time,rs_time,rs_come_time,rs_qudao,rs_fang_kind,rs_laifang,rs_nowqianyue,rs_qianyue_jine,rs_shishou_jine,rs_stu_school,rs_stu_year,rs_stu_jiazhang,rs_tel,rs_stu_name,rs_xueke,rs_beizhu,t.user_zsname,t2.user_zsname as input_username,zss_user_id')->join("lfy_user as t on t.user_id=lfy_rexian_shangmen_data.zss_user_id")->join("lfy_user as t2 on t2.user_id=lfy_rexian_shangmen_data.rs_input_userid")->find();
        //dump($list);
        if(is_null($list)){
            pop('该记录信息不存在或者您无权编辑该条记录信息！',U('ppts/'.$kind));
        }
        $this->assign($list);
        unset($list);
        unset($RE);

         $this->display('ppts:'.$kind);
     }

     public function qt_save_edit_rexianshangmen(){
         //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,131072);
        unset ($System);
        $rs_id=(integer)  addslashes($_POST['rs_id']);
        

         $RE=M('Rexian_shangmen_data');
         $begin_time=time()-(3600*24*30);
        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);
        $list=$RE->where("rs_id={$rs_id} and xq_id={$xq_id} and rs_time>{$begin_time}")->find();
        //dump($list);
        if(is_null($list)){
            unset($RE);
            pop_js('您无权进行该记录的修改保存操作！','self.parent.tb_remove();self.parent.location.reload();');
        }



         $RE->create();
         if($RE->save()){
             unset($RE);
             pop_js('记录修改成功！','self.parent.tb_remove();self.parent.location.reload();');
         }else{
             unset($RE);
             pop_js('无任何修改，不需要进行保存操作！','self.parent.tb_remove();self.parent.location.reload();');
         }
     }



     /**
      * 分公司热线上门管理首页，负责显示各类统计数据
      */
     public function fgs_rexianshangmen_manger(){
         //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,262144);
        unset ($System);

        //获取用户所在分公司部门id
        $PPTS=D('Ppts');
        $fgs_id=$PPTS->get_user_bmid($_SESSION['user_id'],'k');
        unset($PPTS);
        $nowdate=get_date(time());
        $nowmonth=date( 'Y-m', time());
        //dump($nowdate);
        $S=M();
        $sql="select t.bm_id,t.bm_name,"
        ."ifnull("
        ."(select count(t1.rs_id) "
        ."from lfy_rexian_shangmen_data as t1 "
        ."where t1.xq_id=t.bm_id and t1.rs_come_time='{$nowdate}' and t1.rs_kind='热线'),0) "
        ."as now_rexian_num,"
        ."ifnull((select count(t2.rs_id) "
        ."from lfy_rexian_shangmen_data as t2 "
        ."where t2.xq_id=t.bm_id and t2.rs_come_time='{$nowdate}' and t2.rs_kind='上门'),0) as now_shangmen_num,"
        ."ifnull((select sum(t2.rs_qianyue_jine) "
        ."from lfy_rexian_shangmen_data as t2 "
        ."where t2.xq_id=t.bm_id and t2.rs_come_time='{$nowdate}' and t2.rs_kind='上门' and t2.rs_nowqianyue='是'),0) as now_shangmen_qianyue,"
        ."ifnull((select sum(t2.rs_shishou_jine) "
        ."from lfy_rexian_shangmen_data as t2 "
        ."where t2.xq_id=t.bm_id and t2.rs_come_time='{$nowdate}' and t2.rs_kind='上门' and t2.rs_nowqianyue='是'),0) as now_shangmen_shishou,"
        ."ifnull((select count(t2.rs_id) "
        ."from lfy_rexian_shangmen_data as t2 "
        ."where t2.xq_id=t.bm_id and t2.rs_come_time='{$nowdate}' and t2.rs_kind='上门' and rs_fang_kind='约访'),0) as now_shangmen_yuefang_num,"
        ."ifnull((select count(t2.rs_id) "
        ."from lfy_rexian_shangmen_data as t2 "
        ."where t2.xq_id=t.bm_id and t2.rs_come_time='{$nowdate}' and t2.rs_kind='上门' and rs_fang_kind='直访'),0) as now_shangmen_zhifang_num,"
        ."ifnull("
        ."(select count(t3.rs_id) "
        ."from lfy_rexian_shangmen_data as t3 "
        ."where t3.xq_id=t.bm_id and (t3.rs_come_time like '{$nowmonth}%') and t3.rs_kind='热线'),0) "
        ."as month_rexian_num,"
        ."ifnull("
        ."(select count(t3.rs_id) "
        ."from lfy_rexian_shangmen_data as t3 "
        ."where t3.xq_id=t.bm_id and (t3.rs_come_time like '{$nowmonth}%') and t3.rs_kind='上门' and rs_fang_kind='约访' and rs_laifang='0'),0) "
        ."as month_shangmen_yuefang_num,"
        ."ifnull("
        ."(select count(t3.rs_id) "
        ."from lfy_rexian_shangmen_data as t3 "
        ."where t3.xq_id=t.bm_id and (t3.rs_come_time like '{$nowmonth}%') and t3.rs_kind='上门' and rs_fang_kind='直访' and rs_laifang='0'),0) "
        ."as month_shangmen_zhifang_num,"
        ."ifnull("
        ."(select count(t4.rs_id) "
        ."from lfy_rexian_shangmen_data as t4 "
        ."where t4.xq_id=t.bm_id and (t4.rs_come_time like '{$nowmonth}%') and t4.rs_kind='上门' and rs_laifang='0'),0) "
        ."as month_shangmen_num "
        ."from lfy_bumen as t "
        ."where t.bm_main={$fgs_id} and t.bm_kind='s' order by t.bm_name";
        
        //dump($S->query($sql));
        $this->assign('data_list', $S->query($sql));
        unset($S);
        
        $this->display();
     }


      /**
      * 分公司热线上门详细查看
      */
     public function fgs_rexianshangmen_view(){
         //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,262144);
        unset ($System);

        unset($PPTS);
        $RE=M('Rexian_shangmen_data');
        if(isset ($_GET['page_num'])){
            $page_num=(integer)  addslashes($_GET['page_num']);
        }else{
            $page_num=20;
        }
        
        $this->assign('page_num', $page_num);

        import("ORG.Util.Page"); // 导入分页类
        $count=$RE
        ->join("lfy_user as t on t.user_id=lfy_rexian_shangmen_data.zss_user_id")
        ->join("lfy_bumen as t1 on t1.bm_id=lfy_rexian_shangmen_data.xq_id")
        ->order('rs_come_time desc,rs_id desc')->count();
        $Page=new Page($count,$page_num); // 实例化分页类传入总记录数和每页显示的记录数
        $Page->setConfig('theme',"共计%totalRow%条记录 每页{$page_num}条记录　当前%nowPage%/%totalPage% 页 %upPage% %downPage% %first%  %prePage%  <font color=red>%linkPage%</font>  %nextPage% %end%");
        $show=$Page->show(); // 分页显示输出
        $list=$RE
        ->field('rs_kind,rs_come_time,rs_week,rs_qudao,rs_fang_kind,rs_laifang,rs_nowqianyue,rs_qianyue_jine,rs_shishou_jine,user_zsname,rs_stu_jiazhang,rs_stu_school,rs_stu_year,rs_tel,rs_stu_name,rs_xueke,rs_beizhu,rs_id,bm_name')
        ->join("lfy_user as t on t.user_id=lfy_rexian_shangmen_data.zss_user_id")
        ->join("lfy_bumen as t1 on t1.bm_id=lfy_rexian_shangmen_data.xq_id")
        ->order('rs_come_time desc,rs_id desc')
        ->limit($Page->firstRow.','.$Page->listRows)
        ->select();
        unset($RE);
        $this->assign('list', $list);
        $this->assign('page',$show);
        unset($Page);
        unset($list);

        $this->display();
     }

     /**
      * 主要功能：咨询师签约学员管理，主要功能为坏账，查看学员首次签
      * 约合同以及未来开发的扩单相关功能
      */
     public function zx_input_hetong_stu_manger(){
         //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32768);
        unset ($System);

        $S=M();
        $sql="select t.stu_id,t.stu_name,t.stu_sex,t.stu_inputtime,t.td_time,tt.ht_no "
        ."from lfy_stuinfo as t "
        ."left join (lfy_stu_hetong as tt) on (tt.stu_id=t.stu_id) "
        ."where t.user_id={$_SESSION['user_id']} "
        ."and ifnull("
        ."(select count(ht_id) from lfy_stu_hetong as t1 "
        ."where t1.stu_id=t.stu_id),0)>0 "
        ."order by t.stu_inputtime desc";
        $list=$S->query($sql);

        $ZD=M('Zixun_huaizhang_data');
        foreach($list as $info=>$key){
            //dump($key['ht_id']);
            
            $huaizhang=$ZD->where("hd_stu_id={$key['stu_id']}")->count();
            $list[$info]['huaizhang']=$huaizhang;
        }
        unset($ZD);
        //dump($list);


        $this->assign('list', $list);
        unset($list);
        unset($S);
        $this->display();
     }

     /**
      * 主要功能：咨询师查看签约学员首次签约合同详细信息
      */
     public function zx_view_ready_htstu(){
         $stu_id=(integer)  addslashes($_GET['id']);
         //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32768);
        unset ($System);

        $Stu_ht=D('Stu_hetong');
        $ht_info=$Stu_ht->where("stu_id={$stu_id}")->find();
        $ht_id=$ht_info['ht_id'];
        if(is_null($ht_info)){
            pop('该合同信息不存在，请刷新后重新查看合同信息；如果问题一直存在，请联系公司技术部！',U('ppts/z'));
        }
        $this->assign($ht_info);
        unset($Stu_ht);

        $Stuinfo=D('Stuinfo');
        $stu_info=$Stuinfo->where("stu_id={$stu_id}")->find();
        if(is_null($stu_info)){
            pop('该合同不存在学员信息！请检查合同，如有问题请联系技术部处理！', U('ppts/qt_view_ready_inputht_info'));
        }
        $this->assign($stu_info);
        //获取学员基本信息中的建档基本信息
        $this->assign($Stuinfo->get_jiandang($stu_id));
        unset($Stuinfo);


        //获取合同各年级课时信息并赋值到模板
        $Newht=M('Newht_info');
        $this->assign('class_info', $Newht->where("ht_id={$ht_id}")->order('hti_id')->select());
        unset ($Newht);

        /**获取收款信息并赋值到模板
        $SK=M('Qt_htshoukuan');
        //dump($SK->where("ht_id={$ht_id} and lfy_user.user_id=lfy_qt_htshoukuan.sk_input_userid")->table('lfy_user,lfy_qt_htshoukuan')->order('sk_input_time desc')->select());
        $this->assign('shoukuan_info', $SK->where("ht_id={$ht_id} and lfy_user.user_id=lfy_qt_htshoukuan.sk_input_userid")
        ->table('lfy_user,lfy_qt_htshoukuan')
        ->field('user_zsname,lfy_qt_htshoukuan.sk_input_userid,sk_id,sk_kind,sj_no,yh_no,sk_price,sk_yongtu,sk_beizhu,sk_input_time,shenhe')
        ->order('sk_input_time desc')
        ->select());

        unset ($SK);*/

        $this->display();
     }


     /**
      * 咨询师申请坏账页面
      *
      * 填写坏账原因
      */
     public function zx_shenqing_huaizhang(){
         $stu_id=(integer)addslashes($_GET['id']);
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32768);
        unset ($System);
        $this->assign('stu_id',$stu_id);
        $ZD=M('Zixun_huaizhang_data');
        if($ZD->where("hd_stu_id={$stu_id}")->count()>0){
            unset($ZD);
            pop_js('该学员坏账正在审核中，请耐心等待审核结果，请不要重复提交坏账！','self.parent.tb_remove();self.parent.location.reload();');
            
        }

        $Stuinfo=M('Stuinfo');
        $this->assign('stu_name', $Stuinfo->where("stu_id={$stu_id}")->getfield('stu_name'));

         $this->display();
     }

    /**
    * 保存咨询师申请的新签合同坏账学员
    */
    public function zx_save_shenqing_huaizhang(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,32768);
        unset ($System);


        $ZD=M('Zixun_huaizhang_data');
        $ZD->create();
        $ZD->hd_input_userid=$_SESSION['user_id'];
        $ZD->hd_input_time=get_date_full(time());
        if($ZD->add()){
            unset($ZD);
            pop_js('该学员的坏账申请提交成功，请等待进一步审核完成！','self.parent.tb_remove();self.parent.location.reload();');
        }else{
            unset($ZD);
            pop_js('坏账申请失败，系统未知错误！','self.parent.tb_remove();self.parent.location.reload();');
        }
    }

    /**
     * 校监坏账审核列表
     */
    public function xj_huaizhang_shenhe(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,524288);
        unset ($System);

        //获取用户校区id
        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);
        //dump($xq_id);
        $S=M();
        $sql="select * "
        ."from lfy_zxzhuren_huaizhang_shenhe as t "
        ."left join (lfy_zixun_huaizhang_data as t1,lfy_stuinfo as t2,lfy_stu_ht_xiaoqu as t3) "
        ."on (t.zh_hd_id=t1.hd_id and t2.stu_id=t1.hd_stu_id and t3.hx_stu_id=t2.stu_id) "
        ."where t3.hx_xq_id={$xq_id} and t.zh_shenhe_style='1'";

        $list=$S->query($sql);
        //dump($list);
        unset($S);

        $XJ=M('Xj_huaizhang_shenhe');
        foreach($list as $info=>$key){
            //dump($key['ht_id']);
            
            $huaizhang=$XJ->where("xs_hd_id={$key['hd_id']}")->count();
            $list[$info]['huaizhang']=$huaizhang;
        }
        unset($XJ);


        $this->assign('list', $list);

        $this->display();
    }

    /**
     * 校监查看学员合同信息
     */
    public function xj_view_huaizhang_stu_htinfo(){
        $stu_id=(integer)  addslashes($_GET['id']);

        $Stu_ht=D('Stu_hetong');
        $ht_info=$Stu_ht->where("stu_id={$stu_id}")->find();
        $ht_id=$ht_info['ht_id'];
        if(is_null($ht_info)){
            pop('该合同信息不存在，请刷新后重新查看合同信息；如果问题一直存在，请联系公司技术部！',U('ppts/z'));
        }
        $this->assign($ht_info);
        unset($Stu_ht);

        $Stuinfo=D('Stuinfo');
        $stu_info=$Stuinfo->where("stu_id={$stu_id}")->find();
        if(is_null($stu_info)){
            pop('该合同不存在学员信息！请检查合同，如有问题请联系技术部处理！', U('ppts/qt_view_ready_inputht_info'));
        }
        $this->assign($stu_info);
        //获取学员基本信息中的建档基本信息
        $this->assign($Stuinfo->get_jiandang($stu_id));
        unset($Stuinfo);


        //获取合同各年级课时信息并赋值到模板
        $Newht=M('Newht_info');
        $this->assign('class_info', $Newht->where("ht_id={$ht_id}")->order('hti_id')->select());
        unset ($Newht);
        $this->display();
    }

    /**
     * 校监进行坏账信息审核操作界面
     */
    public function xj_huaizhang_shenhe_input(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,524288);
        unset ($System);
        
        $hd_id=(integer)  addslashes($_GET['id']);

        $XJ=M('Xj_huaizhang_shenhe');
        $huaizhang=$XJ->where("xs_hd_id={$hd_id}")->count();
        unset($XJ);
        if($huaizhang>0){
            pop_js('您已经对该条信息进行过审核，请等待上级的审核结果！','self.parent.tb_remove();self.parent.location.reload();');
        }
        
        $ZX=M('Zixun_huaizhang_data');
        $list=$ZX->where("hd_id={$hd_id}")
        ->join("lfy_stuinfo as t on t.stu_id=lfy_zixun_huaizhang_data.hd_stu_id")
        ->join("lfy_zxzhuren_huaizhang_shenhe as t1 on t1.zh_hd_id={$hd_id}")
        ->find();
        //dump($list);
        $this->assign($list);

        $this->assign('hd_id', $hd_id);
        
        $this->display();
    }

    /**
     * 保存校监进行的坏账审核操作
     */
    public function xj_save_huaizhang_shenhe_input(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,524288);
        unset ($System);
        
        $XJ=M('Xj_huaizhang_shenhe');
        $XJ->create();
        $XJ->xs_input_time=get_date_full(time());
        $XJ->xs_user_id=$_SESSION['user_id'];
        if($XJ->add()){
            unset($XJ);
            $ZX=M('Zxzhuren_huaizhang_shenhe');
            $ZX->where("zh_hd_id={$hd_id}")->setField('zh_shenhe','1');
            unset($ZX);
            pop_js('坏账信息审核成功！','self.parent.tb_remove();self.parent.location.reload();');
        }else{
            unset($XJ);
            pop_js('系统未知错误，该坏账信息未审核成功！请重新审核！','self.parent.tb_remove();self.parent.location.reload();');
        }
    }

    /**
     * 咨询主任 坏账审核列表
     */
    public function zxzhuren_huaizhang_shenhe(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,2097152);
        unset ($System);

        //获取用户校区id
        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);
        //dump($xq_id);
        $S=M();
        $sql="select * "
        ."from lfy_zixun_huaizhang_data as t "
        ."left join (lfy_stu_ht_xiaoqu as t1,lfy_stuinfo as t2) "
        ."on (t.hd_stu_id=t1.hx_stu_id and t2.stu_id=t1.hx_stu_id) "
        ."where t1.hx_xq_id={$xq_id} "
        .""
        ."order by t.hd_input_time";
        $list=$S->query($sql);
        //dump($list);
        unset($S);

        $XJ=M('Zxzhuren_huaizhang_shenhe');
        foreach($list as $info=>$key){
            //dump($key['ht_id']);
            
            $huaizhang=$XJ->where("zh_hd_id={$key['hd_id']}")->count();
            $list[$info]['huaizhang']=$huaizhang;
        }
        unset($XJ);


        $this->assign('list', $list);

        $this->display();
    }

    /**
     * 咨询主任进行坏账信息审核操作界面
     */
    public function zxzhuren_huaizhang_shenhe_input(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,2097152);
        unset ($System);

        $hd_id=(integer)  addslashes($_GET['id']);

        $XJ=M('Zxzhuren_huaizhang_shenhe');
        $huaizhang=$XJ->where("zh_hd_id={$hd_id}")->count();
        unset($XJ);
        if($huaizhang>0){
            pop_js('您已经对该条信息进行过审核，请等待上级的审核结果！','self.parent.tb_remove();self.parent.location.reload();');
        }


        $ZX=M('Zixun_huaizhang_data');
        $list=$ZX->where("hd_id={$hd_id}")
        ->join("lfy_stuinfo as t on t.stu_id=lfy_zixun_huaizhang_data.hd_stu_id")
        ->find();
        //dump($list);
        $this->assign($list);

        $this->assign('hd_id', $hd_id);

        $this->display();
    }

    /**
     * 保存咨询主任进行的坏账审核操作
     */
    public function zxzhuren_save_huaizhang_shenhe_input(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,2097152);
        unset ($System);

        $hd_id=(integer)addslashes($_POST['zh_hd_id']);

        $ZH=M('Zxzhuren_huaizhang_shenhe');
        $ZH->create();
        $ZH->zh_input_time=get_date_full(time());
        $ZH->zh_user_id=$_SESSION['user_id'];
        if($ZH->add()){
            unset($ZH);
            $ZX=M('Zixun_huaizhang_data');
            $ZX->where("hd_id={$hd_id}")->setField('hd_shenhe','1');
            unset($ZX);
            pop_js('坏账信息审核成功！','self.parent.tb_remove();self.parent.location.reload();');
        }else{
            unset($ZH);
            pop_js('系统未知错误，该坏账信息未审核成功！请重新审核！','self.parent.tb_remove();self.parent.location.reload();');
        }
    }

    /**
     * 总经理坏账审核列表
     */
    public function zjl_huaizhang_shenhe(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,4194304);
        unset ($System);

        //获取用户校区id
        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);
        //dump($xq_id);
        $S=M();
        $sql="select * "
        ."from lfy_xj_huaizhang_shenhe as t "
        ."left join (lfy_zixun_huaizhang_data as t1,lfy_stuinfo as t2,lfy_stu_ht_xiaoqu as t3,lfy_bumen as t4) "
        ."on (t.xs_hd_id=t1.hd_id and t2.stu_id=t1.hd_stu_id and t3.hx_stu_id=t2.stu_id and t3.hx_xq_id=t4.bm_id) "
        ."where t.xs_shenhe_style='1'";

        $list=$S->query($sql);
        //dump($list);
        unset($S);

        $XJ=M('Zjl_huaizhang_shenhe');
        foreach($list as $info=>$key){
            //dump($key['ht_id']);
            
            $huaizhang=$XJ->where("hs_hd_id={$key['hd_id']}")->count();
            $list[$info]['huaizhang']=$huaizhang;
        }
        unset($XJ);

        $this->assign('list', $list);

        $this->display();
    }


    /**
     * 总经理进行坏账信息审核操作界面
     */
    public function zjl_huaizhang_shenhe_input(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,4194304);
        unset ($System);

        $hd_id=(integer)  addslashes($_GET['id']);

        $XJ=M('Zjl_huaizhang_shenhe');
        $huaizhang=$XJ->where("hs_hd_id={$hd_id}")->count();
        unset($XJ);
        if($huaizhang>0){
            pop_js('您已经对该条信息进行过审核，请等待上级的审核结果！','self.parent.tb_remove();self.parent.location.reload();');
        }

        $ZX=M('Zixun_huaizhang_data');
        $list=$ZX->where("hd_id={$hd_id}")
        ->join("lfy_stuinfo as t on t.stu_id=lfy_zixun_huaizhang_data.hd_stu_id")
        ->join("lfy_zxzhuren_huaizhang_shenhe as t1 on t1.zh_hd_id={$hd_id}")
        ->join("lfy_xj_huaizhang_shenhe as t2 on t2.xs_hd_id={$hd_id}")
        ->find();
        //dump($list);
        $this->assign($list);

        $this->assign('hd_id', $hd_id);

        $this->display();
    }

     /**
     * 保存分公司总经理进行的坏账审核操作
     */
    public function zjl_save_huaizhang_shenhe_input(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,4194304);
        unset ($System);

        $XJ=M('Zjl_huaizhang_shenhe');
        $XJ->create();
        $XJ->hs_input_time=get_date_full(time());
        $XJ->hs_user_id=$_SESSION['user_id'];
        if($XJ->add()){
            unset($XJ);
            $ZX=M('Xj_huaizhang_shenhe');
            $ZX->where("xs_hd_id={$hd_id}")->setField('xs_shenhe','1');
            unset($ZX);
            pop_js('坏账信息审核成功！','self.parent.tb_remove();self.parent.location.reload();');
        }else{
            unset($XJ);
            pop_js('系统未知错误，该坏账信息未审核成功！请重新审核！','self.parent.tb_remove();self.parent.location.reload();');
        }
    }

    /**
     * 分公司财务进行坏账审核界面逻辑
     */
    public function cw_huaizhang_shenhe(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,1048576);
        unset ($System);

        $S=M();
        $sql="select * "
        ."from lfy_zjl_huaizhang_shenhe as t "
        ."left join (lfy_zixun_huaizhang_data as t1,lfy_stuinfo as t2,lfy_stu_ht_xiaoqu as t3,lfy_bumen as t4) "
        ."on (t.hs_hd_id=t1.hd_id and t2.stu_id=t1.hd_stu_id and t3.hx_stu_id=t2.stu_id and t3.hx_xq_id=t4.bm_id) "
        ."where t.hs_shenhe_style='1'";

        $list=$S->query($sql);
        //dump($list);
        unset($S);

        $XJ=M('Caiwu_huaizhang_shenhe');
        foreach($list as $info=>$key){
            //dump($key['ht_id']);
            
            $huaizhang=$XJ->where("cw_hd_id={$key['hd_id']}")->count();
            $list[$info]['huaizhang']=$huaizhang;
        }
        unset($XJ);


        $this->assign('list', $list);



        $this->display();
    }

    /**
     * 分公司财务进行坏账信息审核操作界面
     */
    public function cw_huaizhang_shenhe_input(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,4194304);
        unset ($System);

        $hd_id=(integer)addslashes($_GET['id']);

        $XJ=M('Caiwu_huaizhang_shenhe');
        $huaizhang=$XJ->where("cw_hd_id={$hd_id}")->count();
        unset($XJ);
        if($huaizhang>0){
            pop_js('您已经对该条信息进行过审核，请等待上级的审核结果！','self.parent.tb_remove();self.parent.location.reload();');
        }

        $ZX=M('Zixun_huaizhang_data');
        $list=$ZX->where("hd_id={$hd_id}")
        ->join("lfy_stuinfo as t on t.stu_id=lfy_zixun_huaizhang_data.hd_stu_id")
        ->join("lfy_zxzhuren_huaizhang_shenhe as t1 on t1.zh_hd_id={$hd_id}")
        ->join("lfy_xj_huaizhang_shenhe as t2 on t2.xs_hd_id={$hd_id}")
        ->join("lfy_zjl_huaizhang_shenhe as t3 on t3.hs_hd_id={$hd_id}")
        ->find();
        //dump($list);
        $this->assign($list);

        $this->assign('hd_id', $hd_id);

        $this->display();
    }


    /**
     * 保存分公司财务进行的坏账审核操作
     */
    public function cw_save_huaizhang_shenhe_input(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,524288);
        unset ($System);

        $XJ=M('Caiwu_huaizhang_shenhe');
        $XJ->create();
        $XJ->cw_input_time=get_date_full(time());
        $XJ->cw_user_id=$_SESSION['user_id'];
        if($XJ->add()){
            unset($XJ);
            $ZX=M('Zjl_huaizhang_shenhe');
            $ZX->where("hs_hd_id={$hd_id}")->setField('hs_shenhe','1');
            unset($ZX);
            pop_js('坏账信息审核成功！','self.parent.tb_remove();self.parent.location.reload();');
        }else{
            unset($XJ);
            pop_js('系统未知错误，该坏账信息未审核成功！请重新审核！','self.parent.tb_remove();self.parent.location.reload();');
        }
    }


    /**
     * 坏账审核各级查看坏账流转状态
     */
    public function zx_huaizhang_style(){
        $stu_id=(integer)addslashes($_GET['id']);

//        $sql="select * "
//        ."from lfy_zixun_huaizhang_data as t "
//        ."left join (lfy_zxzhuren_huaizhang_shenhe as t1,lfy_xj_huaizhang_shenhe as t2,lfy_zjl_huaizhang_shenhe as t3) "
//        ."on (t1.zh_hd_id=t.hd_id "
//        ."and t2.xs_hd_id=t.hd_id "
//        ."and t3.hs_hd_id=t.hd_id) "
//        ."where t.hd_stu_id={$stu_id}";

        $sql="select * "
        ."from lfy_zixun_huaizhang_data as t "
        ."left join (lfy_zxzhuren_huaizhang_shenhe as t1) "
        ."on (t1.zh_hd_id=t.hd_id) "
        ."left join (lfy_xj_huaizhang_shenhe as t2) on (t2.xs_hd_id=t.hd_id) "
        ."left join (lfy_zjl_huaizhang_shenhe as t3) on (t3.hs_hd_id=t.hd_id) "
        ."left join (lfy_caiwu_huaizhang_shenhe as t4) on (t4.cw_hd_id=t.hd_id) "
        ."where t.hd_stu_id={$stu_id}";
        $S=M();
        $list=$S->query($sql);
        //dump($list);
        unset($S);
        $this->assign($list[0]);
        unset($list);
        


        $this->display();
    }

    /**
     * 校监查看本校区的各项业绩统计数据
     */
    public function xj_xiaoqu_tongji(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,16777216);
        unset ($System);

        //获取用户所在校区的部门id
        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);

        //dump($xq_id);
        //获取当月的年月数据
        $nowmonth=date( 'Y-m', time());

        //计算校区合同新签额
        $sql="select ifnull(sum(t.hetong_price),0) as ht_sum,ifnull(count(t.ht_id),0) as ht_count "
        ."from lfy_stu_hetong as t "
        ."left join lfy_stu_xiaoqu as t1 "
        ."on t.stu_id=t1.stu_id "
        ."where t.ht_input_time like '{$nowmonth}%' and t1.xq_id={$xq_id}";
        $S=M();
        $list=$S->query($sql);
        $this->assign($list[0]);
        unset($list);
        unset($sql);

        //计算校区合同新签实收额
        $sql="select ifnull(sum(sk_price),0) as ht_shishou "
        ."from lfy_qt_htshoukuan as t "
        ."left join lfy_stu_xiaoqu as t1 "
        ."on t.stu_id=t1.stu_id "
        ."where t.sk_input_time like '{$nowmonth}%' "
        ."and t1.xq_id={$xq_id}";
        $list=$S->query($sql);
        $this->assign($list[0]);
        unset($list);
        unset($sql);

        $nowdate=get_date(time());
        //获取校区当天的上门数量
        $RE=M('Rexian_shangmen_data');
        $nowdate_shangmen_count=$RE->where("rs_kind='上门' and rs_come_time='{$nowdate}' and xq_id={$xq_id}")->count();
        if(is_null($nowdate_shangmen_count)){
            $nowdate_shangmen_count=0;
        }
        $this->assign('nowdate_shangmen_count', $nowdate_shangmen_count);

        //获取校区当天的热线数量
        $nowdate_rexian_count=$RE->where("rs_kind='热线' and rs_come_time='{$nowdate}' and xq_id={$xq_id}")->count();
        if(is_null($nowdate_rexian_count)){
            $nowdate_rexian_count=0;
        }
        $this->assign('nowdate_rexian_count', $nowdate_rexian_count);


        $nowmonth=date( 'Y-m', time());
        //获取校区当月的热线数量
        $nowmonth_rexian_count=$RE->where("rs_kind='热线' and xq_id={$xq_id} and (rs_come_time like '{$nowmonth}%')")->count();
        if(is_null($nowmonth_rexian_count)){
            $nowmonth_rexian_count=0;
        }
        $this->assign('nowmonth_rexian_count', $nowmonth_rexian_count);


        //获取校区当月的上门数量
        $nowmonth_shangmen_count=$RE->where("rs_kind='上门' and xq_id={$xq_id} and (rs_come_time like '{$nowmonth}%')")->count();
        //dump($RE->where("rs_kind='上门' and xq_id={$xq_id} and (rs_come_time like '{$nowmonth}%')")->select());
        if(is_null($nowmonth_shangmen_count)){
            $nowmonth_shangmen_count=0;
        }
        $this->assign('nowmonth_shangmen_count', $nowmonth_shangmen_count);

        unset($RE);
        

        $this->display();
    }
    
    /**
     * 学管主任-本校区签约学员管理
     * 进入条件：签约学员、全款、合同提档到本校区
     */
    public function xgzr_stu_manger(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,33554432);
        unset ($System);

        
        //获取用户所在校区的部门id
        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);
        
        $sql="select t.stu_id,t1.stu_no,t1.stu_name,t1.stu_sex,t3.user_zsname as zx_name,t1.td_time,t.ht_id,t6.user_zsname as xg_name "
        ."from lfy_stu_hetong as t "
        ."left join lfy_stuinfo as t1 on t.stu_id=t1.stu_id "
        ."left join lfy_stu_ht_xiaoqu as t2 on t.stu_id=t2.hx_stu_id "
        ."left join lfy_zx_newht as t4 on zn_ht_id=t.ht_id "
        ."left join lfy_user as t3 on t3.user_id=t4.zn_user_id "
        ."left join lfy_xueguan_jiedang as t5 on t.stu_id=t5.stu_id "
        ."left join lfy_user as t6 on t5.user_id=t6.user_id "
        ."where (select ifnull(sum(sk_price),0) from lfy_qt_htshoukuan as s where s.ht_id=t.ht_id)=t.hetong_price "
        ."and t2.hx_xq_id={$xq_id} "
        ."order by t1.td_time desc";
        $S=M();
        //dump($S->query($sql));
        $this->assign('list', $S->query($sql));
        unset($S);

        $this->display();
        
    }


    /**
     * 学管主任进行学员ID的分配
     */
    public function xgzr_fenpei_stuno(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,33554432);
        unset ($System);
        $stu_id=(integer)  addslashes($_GET['id']);

        $this->assign('stu_id', $stu_id);

        //获取界面上的学员姓名
        $Stuinfo=M('Stuinfo');
        $this->assign('stu_name', $Stuinfo->where("stu_id={$stu_id}")->getfield('stu_name'));
        unset($Stuinfo);

        

        $this->display();
    }


    /**
     * 保存学管主任分配的学员ID
     */
    public function xgzr_save_fenpei_stuno(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,33554432);
        unset ($System);

        //获取界面上的学员姓名
        $Stuinfo=M('Stuinfo');
        $Stuinfo->create();
        //dump($Stuinfo);
        //exit();
        if($Stuinfo->save()){
            unset($Stuinfo);
            pop_js('学员ID分配成功！','self.parent.tb_remove();self.parent.location.reload();');
        }else{
            unset($Stuinfo);
            pop_js('系统未知性错误，请重新进行学员ID的分配！','self.parent.tb_remove();self.parent.location.reload();');
        }
    }

    /**
     * 学管主任进行学管的分配
     */
    public function xgzr_fenpei_xueguan(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,33554432);
        unset ($System);
        $stu_id=(integer)  addslashes($_GET['id']);
        
        //将学员系统id赋值到模板
        $this->assign('stu_id', $stu_id);

        //获取界面上的学员姓名
        $Stuinfo=M('Stuinfo');
        $this->assign('stu_name', $Stuinfo->where("stu_id={$stu_id}")->getfield('stu_name'));
        unset($Stuinfo);


        $M=M();
        //获取用户所在校区的部门id
        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);

        //获取本校区所有的学管资料
        $sql="select t.user_id,t1.user_zsname "
        ."from lfy_user_shenfen as t "
        ."left join lfy_user as t1 on t.user_id=t1.user_id "
        ."left join lfy_user_bumen as t2 on t2.user_id=t.user_id "
        ."where t2.bm_kind='s' "
        ."and t2.bm_id={$xq_id} "
        ."and t.sf_kind='s' "
        ."order by t1.user_no";
        $this->assign('list',$M->query($sql));
        unset($M);

        $this->display();
    }

    /**
     * 保存学管主任分配的学管控制器
     */
    public function xgzr_save_fenpei_xueguan(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,33554432);
        unset ($System);

        $Xueguan_jiedang=M('Xueguan_jiedang');
        $Xueguan_jiedang->create();
        $Xueguan_jiedang->xj_time=get_date_full(time());
        //dump($Xueguan_jiedang);
        if($Xueguan_jiedang->add()){
            unset($Xueguan_jiedang);
            pop_js('学管分配成功！','self.parent.tb_remove();self.parent.location.reload();');
        }else{
            unset($Xueguan_jiedang);
            pop_js('系统未知性错误，请重新进行学管的分配！','self.parent.tb_remove();self.parent.location.reload();');
        }
        
    }


    /**
     * 学管主任进行本校区学员信息的查看并加入首次签约合同，续费
     * 合同，学员基本信息等的查看
     */
    public function xgzr_view_stuinfo(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,33554432);
        unset ($System);

        
        $stu_id=(integer)  addslashes($_GET['id']);

        $this->assign('stu_id', $stu_id);

        $Stuinfo=M('Stuinfo');
        $list=$Stuinfo->where("lfy_stuinfo.stu_id={$stu_id}")
        ->join("lfy_stu_xiaoqu on lfy_stu_xiaoqu.stu_id=lfy_stuinfo.stu_id")
        ->join("lfy_bumen on lfy_stu_xiaoqu.xq_id=lfy_bumen.bm_id")
        ->join("lfy_user on lfy_user.user_id=lfy_stuinfo.user_id")
                ->find();
        //dump($list);
        unset ($Stuinfo);
        if(is_null($list)){
            pop_js('您没有权限浏览该条记录！','self.parent.tb_remove();self.parent.location.reload();');
        }
        $this->assign($list);

        unset ($list);

        $this->display();
    }

    /**
     * 学管进行续费申请的提交界面
     */
    public function xg_stu_hetong_xufei(){
        $stu_id=(integer)addslashes($_GET['id']);

        $this->assign('stu_id',$stu_id);

        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,1024);
        unset ($System);


        $Stuinfo=M('Stuinfo');
        $this->assign('stu_name', $Stuinfo->where("stu_id={$stu_id}")->getfield('stu_name'));
        unset($Stuinfo);


        $this->display();
    }

    /**
     * 保存学管进行的续费申请
     */
    public function xg_save_stuht_xufei_shenqing(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,1024);
        unset ($System);

        $stu_id=(integer)addslashes($_GET['id']);

        //获取用户所在校区的部门id
        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);

        $data=array(
            'xx_stu_id'=>$stu_id,
            'xx_user_id'=>$_SESSION['user_id'],
            'xx_shenqing_time'=>  get_date_full(time()),
            'xx_xq_id'=>$xq_id
        );
        $Xufei=M('Xueguan_xufeishenqing');
        if($Xufei->add($data)){
            pop_js('续费申请提交成功，请不要重复提交续费申请！','self.parent.tb_remove();self.parent.location.reload();');
            unset($Xufei);
        }else{
            pop_js('系统异常错误，请稍后重新尝试进行续费申请！','self.parent.tb_remove();self.parent.location.reload();');
            unset($Xufei);
        }
        
        
    }

    /**
     * 前台续费学员管理-默认为申请续费并未录入续费合同学员列表显示
     */
    public function qt_xufei_stu_manger(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,67108864);
        unset ($System);

        //获取用户所在校区的部门id
        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);

        $Xueguan_xufeishenqing=M('Xueguan_xufeishenqing');
        $M=M();
        $sql="select t.xx_id,t1.stu_name,t1.stu_no,t1.stu_sex,t.xx_stu_id as stu_id,t2.user_zsname as xg_name,t.xx_shenqing_time as sq_time "
        ."from lfy_xueguan_xufeishenqing as t "
        ."left join lfy_stuinfo as t1 on t.xx_stu_id=t1.stu_id "
        ."left join lfy_user as t2 on t2.user_id=t.xx_user_id "
        ."where t.xx_xq_id={$xq_id} "
        ."and ifnull((select count(xh_id) from lfy_stu_xufei_hetong where xh_xx_id=t.xx_id),0)<=0 "
        ."and t.xx_delete='0' "
        ."order by sq_time";


        


        $this->assign('list',$M->query($sql));
        unset($M);
        
        
        $this->display();
    }


    /**
     * 前台对续费申请进行删除处理
     *
     * 本位置应增加一个记录表
     */
    public function qt_del_xufei_shenqing(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,67108864);
        unset ($System);
        
        $xx_id=(integer)  addslashes($_GET['id']);
        $Xueguan_xufeishenqing=M('Xueguan_xufeishenqing');
        if($Xueguan_xufeishenqing->where("xx_id={$xx_id}")->setField('xx_delete','1')){
            unset($Xueguan_xufeishenqing);
            pop_js('该续费申请已经删除成功，该操作已经记录在案！','self.parent.tb_remove();self.parent.location.reload();');
        }else{
            unset($Xueguan_xufeishenqing);
            pop_js('系统异常错误，请稍后重新进行续费申请的删除！','self.parent.tb_remove();self.parent.location.reload();');
        }
    }


    /**
      * 咨询自身热线上门查看
      *
      * 角色：咨询师
      */
     public function zx_rexianshangmen(){
         //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,16);
        unset ($System);
        $kind=$_GET['kind'];
        if($kind=='shangmen'){
            $kind='zx_rexianshangmen_shangmen';
            $str='上门';
        }else{
            $kind='zx_rexianshangmen_rexian';
            $str='热线';
        }


        $RE=M('Rexian_shangmen_data');
        $begin_time=time()-(3600*24*30);
        //$list=$RE->where("rs_kind='上门' and rs_time>{$begin_time} and xq_id={$xq_id}")->join("lfy_user as t on t.user_id=lfy_rexian_shangmen_data.zss_user_id")->order('rs_come_time desc')->select();
        //dump($list);

        import("ORG.Util.Page"); // 导入分页类
        $count=$RE->where("rs_kind='{$str}' and rs_time>{$begin_time} and zss_user_id={$_SESSION['user_id']}")->join("lfy_user as t on t.user_id=lfy_rexian_shangmen_data.zss_user_id")->order('rs_come_time desc')->count();
        $Page=new Page($count,20); // 实例化分页类传入总记录数和每页显示的记录数
        $Page->setConfig('theme',"共计%totalRow%条记录 每页20条记录　当前%nowPage%/%totalPage% 页 %upPage% %downPage% %first%  %prePage%  <font color=red>%linkPage%</font>  %nextPage% %end%");
        $show=$Page->show(); // 分页显示输出
        $list=$RE->
        where("rs_kind='{$str}' and rs_time>{$begin_time} and zss_user_id={$_SESSION['user_id']}")
        ->field('rs_come_time,rs_qudao,rs_fang_kind,rs_laifang,rs_nowqianyue,rs_qianyue_jine,user_zsname,rs_stu_jiazhang,rs_stu_name,rs_id')
        ->join("lfy_user as t on t.user_id=lfy_rexian_shangmen_data.zss_user_id")
        ->order('rs_come_time desc')
        ->limit($Page->firstRow.','.$Page->listRows)
        ->select();
        unset($RE);
        $this->assign('list', $list);
        //dump($list);
        $this->assign('page',$show);
        unset($Page);
        unset($list);

        $this->display('ppts:'.$kind);
     }

     /**
      * 咨询师进行查看热线上门情况详细信息控制器
      */
     public function zx_view_rexianshangmen_info(){
         //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,16);
        unset ($System);
         $kind=$_GET['kind'];
         if($kind=='shangmen'){
             $kind='qt_view_rexianshangmen_shangmen_info';
         }else{
             $kind='qt_view_rexianshangmen_rexian_info';
         }
        $rs_id=(integer)  addslashes($_GET['id']);
        $RE=M('Rexian_shangmen_data');
        $begin_time=time()-(3600*24*30);
        $PPTS=D('Ppts');
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');
        unset($PPTS);
        $list=$RE->where("rs_id={$rs_id} and zss_user_id={$_SESSION['user_id']} and rs_time>{$begin_time}")->field('rs_input_time,rs_time,rs_come_time,rs_qudao,rs_fang_kind,rs_laifang,rs_nowqianyue,rs_qianyue_jine,rs_shishou_jine,rs_stu_school,rs_stu_year,rs_stu_jiazhang,rs_tel,rs_stu_name,rs_xueke,rs_beizhu,t.user_zsname,t2.user_zsname as input_username')->join("lfy_user as t on t.user_id=lfy_rexian_shangmen_data.zss_user_id")->join("lfy_user as t2 on t2.user_id=lfy_rexian_shangmen_data.rs_input_userid")->find();
        //dump($list);
        if(is_null($list)){
            pop('该记录信息不存在或者您无权查看该条记录信息！',U('ppts/'.$kind));
        }
        $this->assign($list);
        unset($list);
        unset($RE);


         $this->display('ppts:'.$kind);
     }

     /**
      * 前台录入续费合同界面逻辑
      * 操作人为：校区前台
      */
     public function qt_input_stu_xufeihetong(){
         //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,67108864);
        unset ($System);
        
        //建立PPTS数据处理模型
        $PPTS=D('Ppts');
        

        //进行获取用户所在的校区部门id号码
        $xq_id=$PPTS->get_user_bmid($_SESSION['user_id'],'s');

        $fgs_id=$PPTS->get_user_bmid($_SESSION['user_id'],'k');
        //将校区id赋值到模板
        $this->assign('xq_id',$xq_id);
        //将分公司的部门id赋值到模板
        $this->assign('fgs_id', $fgs_id);
        //dump($fgs_id);
        
        unset($PPTS);

        
        //获取续费申请的流水id
        $xx_id=(integer)  addslashes($_GET['id']);

        $this->assign('xx_id', $xx_id);

        $Xueguan_xufeishenqing=M('Xueguan_xufeishenqing');
        $xf_info=$Xueguan_xufeishenqing->where("xx_id={$xx_id}")->join("lfy_user on lfy_user.user_id=lfy_xueguan_xufeishenqing.xx_user_id")->find();
        if(is_null($xf_info)){
            pop('该续费信息不存在，有可能已经完成处理！或者系统异常，请宠幸操作！',U('ppts/qt_xufei_stu_manger'));
        }
        //dump($xf_info);

        $this->assign($xf_info);

        $Stuinfo=M('Stuinfo');
        $this->assign($Stuinfo->where("stu_id={$xf_info['xx_stu_id']}")->find());
        


        $KP=M('Kecheng_price');  //建立课程价格模型
        $kp_list=$KP->where("kp_bmid={$fgs_id}")->field('distinct kp_name')->select();
        unset ($KP);  //销毁
        //将不重复的价格年级（名称）赋值到模板
        $this->assign('kpname_list', $kp_list);

         $this->display();
     }


     /**
      * 分公司咨询师月实收统计功能
      */
     public function zx_yueshishou_tongji(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,4096);
        unset ($System);

        /*
         *  SQL语句 查询所有咨询师月实收情况
         **/
         $Income = M('Income');//实例化新对象
         /*import("ORG.Util.Page"); ; //导入分页类
         $count=$Income->where("sf_kind='z'")->count();
         $page =new Page($count,20);
         $page->setConfig('theme',"共计%totalRow%条记录 每页20条记录　当前%nowPage%/%totalPage% 页 %upPage% %downPage% %first%  %prePage%  <font color=red>%linkPage%
		 </font>  %nextPage% %end%");
         $show=$page->show(); // 分页显示输出*/

      	 $sql="SELECT SUM(t4.sk_price) AS s,t1.user_id,t1.user_no,t1.user_zsname,t1.bm_id,t2.sf_kind,t3.* ,t4.sk_input_time,t5.bm_name
      	 		 FROM lfy_user AS t1
				 JOIN lfy_user_shenfen AS t2 ON t1.user_id=t2.user_id
				 JOIN lfy_zx_newht AS t3 ON t2.user_id=t3.zn_user_id
				 JOIN lfy_qt_htshoukuan AS t4 ON t3.zn_ht_id=t4.ht_id
                                 JOIN lfy_user_bumen as tt on tt.user_id=t1.user_id
                                 JOIN lfy_bumen AS t5 on t5.bm_id=tt.bm_id
				WHERE t2.sf_kind='z' and tt.bm_kind='s'
                                GROUP BY t1.user_no ORDER BY t4.sk_input_time DESC";
         $this->assign('list',$Income->query($sql));
         
         //页码赋值到模板
         /*$this->assign('page', $show);*/
         $this->display();
    }

    /**
     * 分公司月实收统计查看咨询师的详细信息
     */
    public function zx_yueshishou_manger_info(){
    	 //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,4096);
        unset ($System);
        /*
         *  GET 方法接受参数
         **/
        $kind=$_GET['kind'];
        if($kind=='manger')
        {
        	$kind='zx_yueshishou_manger_info';
        }

        $user_id=(int)($_GET['id']);

    	$M=M();
        $PPTS=D('Ppts');
        unset($PPTS);
       $list="SELECT SUM(t4.sk_price) AS s,t1.user_id,t1.user_no,t1.user_zsname,t1.bm_id,t2.sf_kind,t3.* ,t4.sk_input_time,t5.bm_name
      	 		FROM lfy_user AS t1
				JOIN lfy_user_shenfen AS t2 ON t1.user_id=t2.user_id
				JOIN lfy_zx_newht AS t3 ON t2.user_id=t3.zn_user_id
				JOIN lfy_qt_htshoukuan AS t4 ON t3.zn_ht_id=t4.ht_id
				JOIN lfy_bumen AS t5 on t5.bm_id=t1.bm_id
				WHERE t2.sf_kind='z' GROUP BY t1.user_no ORDER BY t4.sk_input_time DESC";

        $this->assign('list',$M->query($list));

        /*$list=$RE->where("user_id={$user_id}")
        ->field('SUM(sk_price)/2 AS s,lfy_user.user_id,lfy_user.user_no,lfy_user.user_zsname,lfy_user.bm_id,t2.bm_kind,t3.sf_kind,t4.* ,t5.sk_input_time ')
        ->join("lfy_user_bumen AS t2 ON lfy_user.user_id=t2.user_id")
        ->join("lfy_user_shenfen AS t3 ON t2.user_id=t3.user_id")
        ->join("lfy_zx_newht AS t4 ON t3.user_id=t4.zn_user_id")
        ->join("lfy_qt_htshoukuan AS t5 ON t4.zn_ht_id=t5.ht_id")
        ->group("lfy_user.user_no")->order("sk_input_time DESC")->find();*/

        if(is_null($list)){
            pop('该记录信息不存在或者您无权查看该条记录信息！',U('ppts/'.$kind));
        }
        $this->assign($list);
        unset($list);
        unset($RE);

        $this->display('ppts:'.$kind);
    }


    /**
     * 前台保存录入的续费合同
     */
    public function qt_save_input_xufeihetong(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,67108864);
        unset ($System);

        $Stu_xufei_hetong=M('Stu_xufei_hetong');
        $Stu_xufei_hetong->create();
        $Stu_xufei_hetong->xh_input_time=get_date_full(time());
        $Stu_xufei_hetong->xh_user_id=$_SESSION['user_id'];
        
        
        //续费申请流水号id
        $xx_id=(integer)  addslashes($_POST['xh_xx_id']);
        
        $Xueguan_xufeishenqing=M('Xueguan_xufeishenqing');
        $xf_info=$Xueguan_xufeishenqing->where("xx_id={$xx_id}")->find();
        if(is_null($xf_info)){
            unset($Xueguan_xufeishenqing);
            pop('该条学费申请存在异常，请返回重新操作！',U('ppts/qt_xufei_stu_manger'));
        }
        unset($Xueguan_xufeishenqing);
        
        $xh_id=$Stu_xufei_hetong->add();
        
        if(is_null($xh_id)){
            unset($Stu_xufei_hetong);
            pop('系统异常错误，请返回后重试！',U('ppts/qt_xufei_stu_manger'));
        }
        //续费合同关系对应表数据
        $data=array(
            'hv_xh_id'=>$xh_id,
            'hv_xq_id'=>$xf_info['xx_xq_id'],
            'hv_user_id'=>$xf_info['xx_user_id'],
            'hv_stu_id'=>$Stu_xufei_hetong->xh_stu_id
        );
        unset($Stu_xufei_hetong);
        //dump($data);
        $Xufei_hetong_vs=M('Xufei_hetong_vs');
        //dump($Xufei_hetong_vs->add($data));
        //exit();
        
        //处理学员续费购买课时逻辑功能
        $New=M('Xufeiht_info');
        for($i=1;$i<=8;$i++){
            if($_POST['gm_keshi_'.$i]>0){
                if($_POST['class_kind_'.$i]=='11')
                    $class_kind='普通一对一';
                elseif($_POST['class_kind_'.$i]=='31')
                    $class_kind='3A一对一';
                elseif($_POST['class_kind_'.$i]=='32')
                    $class_kind='3A一对多';
                elseif($_POST['class_kind_'.$i]=='12')
                    $class_kind='普通一对多';
                $n_data=array(
                    'xi_class'=>addslashes($_POST['class_year_'.$i]),
                    'xi_kind'=>$class_kind,
                    'xi_gmkeshi'=>(integer) addslashes($_POST['gm_keshi_'.$i]),
                    'xi_old_danjia'=>(integer) addslashes($_POST['old_price_'.$i]),
                    'xi_new_danjia'=>(integer) addslashes($_POST['sj_price_'.$i]),
                    'xi_sum_price'=>(integer) addslashes($_POST['gm_sum_'.$i]),
                    'xi_input_time'=>  get_date_full(time()),
                    'xi_userid'=>$_SESSION['user_id'],
                    'xi_xh_id'=>$xh_id
                );
                $New->add($n_data);
            }
        }
        unset ($New);
        
        if(!$Xufei_hetong_vs->add($data)){
            unset($Xufei_hetong_vs);
            pop('续费合同关系操作异常，请返回重新操作！',U('ppts/qt_xufei_stu_manger'));
        }
        unset($Xufei_hetong_vs);
        
        if($xh_id){
            pop('续费合同录入成功，系统将自动返回未录续费合同管理界面！！',U('ppts/qt_xufei_stu_manger'));
        }
    }
    
    
    /**
     * 前台续费合同管理界面
     * 
     * 该方法主要负责进行续费合同列表的显示
     */
    public function qt_xufei_hetong_manger(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,67108864);
        unset ($System);
        
        $SQL=M();
        $sql="select * "
        ."from lfy_stu_xufei_hetong as t "
        ."left join lfy_stuinfo as t1 on t1.stu_id=t.xh_stu_id "
        ."left join lfy_xufei_hetong_vs as t2 on t2.hv_xh_id=t.xh_id "
        ."left join lfy_user as t3 on t3.user_id=t2.hv_user_id "
        ."order by t.xh_input_time desc";
        $list=$SQL->query($sql);
        
        //以下为计算合同的收款信息
        $SK=M('Qt_xufeishoukuan');
        foreach($list as $info=>$key){
            //dump($key['xh_id']);
            $sum=$SK->field('ifnull(sum(xf_price),0) as ready_price')->where("xf_xh_id={$key['xh_id']}")->select();
            //echo $SK->getlastsql();
            //dump($sum);
//            if(is_null($sum['0']['ready_price']))
//                $sum['0']['ready_price']=0;
            $list[$info]['ready_price']=$sum['0']['ready_price'];
        }
        unset($SK);
        
        
        //dump($list);
        $this->assign('list', $list);
        
        $this->display();
    }
    
    
    /**
     * 前台续费合同收款界面
     */
    public function qt_xufei_hetong_shoukuan(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,67108864);
        unset ($System);
        
        //获取学员id
        $stu_id=(integer) addslashes($_GET['id']);
        $this->assign('stu_id', $stu_id);
        
        //获取所属续费合同系统id
        $xh_id=(integer) addslashes($_GET['k_id']);
        $this->assign('xh_id', $xh_id);

        $Stu=M('Stuinfo');
        //获取学员的姓名
        $stu_name=$Stu->where("stu_id={$stu_id}")->getfield('stu_name');
        unset ($Stu);
        $this->assign('stu_name', $stu_name);
        
        
        $this->display();
    }
    
    /**
     * 操作对象：前台
     * 
     * 前台续费收款保存功能
     */
    public function save_qt_xufeihetong_sk(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,67108864);
        unset ($System);
        
        
        $Qt_xufeishoukuan=M('Qt_xufeishoukuan');
        if(!$Qt_xufeishoukuan->create()){
            unset($Qt_xufeishoukuan);
            pop_js('系统收款异常，请返回后重新收款！','self.parent.tb_remove();self.parent.location.reload();');
        }
        $Qt_xufeishoukuan->xf_input_time=get_date_full(time());
        $Qt_xufeishoukuan->xf_input_userid=$_SESSION['user_id'];
        
        if($Qt_xufeishoukuan->add()){
            unset($Qt_xufeishoukuan);
            pop_js('续费收款成功！','self.parent.tb_remove();self.parent.location.reload();');
        }else{
            unset($Qt_xufeishoukuan);
            pop_js('系统收款异常，请返回后重新进行收款操作！','self.parent.tb_remove();self.parent.location.reload();');
        }
        unset($Qt_xufeishoukuan);
    }
    
    /*
     * 前台查看续费合同信息
     */
    public function qt_view_xufei_hetong(){
        //权限检测
        $System=D('System');
        $System->check_qx_model($_SESSION['qx_id'],3,67108864);
        unset ($System);
        
        $xh_id=(integer)  addslashes($_GET['id']);
        //dump($xh_id);
        $Stu_xufei_hetong=M('Stu_xufei_hetong');
        $list=$Stu_xufei_hetong
        ->join("lfy_stuinfo as t1 on t1.stu_id=lfy_stu_xufei_hetong.xh_stu_id")
        ->join("lfy_xueguan_xufeishenqing as t2 on t2.xx_id=lfy_stu_xufei_hetong.xh_xx_id")
        ->join("lfy_xufei_hetong_vs as t4 on t4.hv_xh_id=lfy_stu_xufei_hetong.xh_id")
        ->join("lfy_user as t3 on t3.user_id=t4.hv_user_id")
        ->where("xh_id={$xh_id}")
        ->find();
        //dump($list);
        
        $this->assign($list);
        
        
        
        
        $this->display();
    }

}
?>
